1# Groups the DataFrame using the specified columns
2
3df.groupBy().avg().collect()
4# [Row(avg(age)=3.5)]
5sorted(df.groupBy('name').agg({'age': 'mean'}).collect())
6# [Row(name='Alice', avg(age)=2.0), Row(name='Bob', avg(age)=5.0)]
7sorted(df.groupBy(df.name).avg().collect())
8# [Row(name='Alice', avg(age)=2.0), Row(name='Bob', avg(age)=5.0)]
9sorted(df.groupBy(['name', df.age]).count().collect())
10# [Row(name='Alice', age=2, count=1), Row(name='Bob', age=5, count=1)]