Horje
Groups the DataFrame using the specified columns Code Example
Groups the DataFrame using the specified columns
# Groups the DataFrame using the specified columns

df.groupBy().avg().collect()
# [Row(avg(age)=3.5)]
sorted(df.groupBy('name').agg({'age': 'mean'}).collect())
# [Row(name='Alice', avg(age)=2.0), Row(name='Bob', avg(age)=5.0)]
sorted(df.groupBy(df.name).avg().collect())
# [Row(name='Alice', avg(age)=2.0), Row(name='Bob', avg(age)=5.0)]
sorted(df.groupBy(['name', df.age]).count().collect())
# [Row(name='Alice', age=2, count=1), Row(name='Bob', age=5, count=1)]




Python

Related
how to convert adjacency list to adjacency matrix Code Example how to convert adjacency list to adjacency matrix Code Example
python logger get level Code Example python logger get level Code Example
how to input a string in streamlit Code Example how to input a string in streamlit Code Example
python print datetime Code Example python print datetime Code Example
union dataframe pyspark Code Example union dataframe pyspark Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7