Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)]
Comment

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)]
Comment

PREVIOUS NEXT
Code Example
Python :: numpy random for string 
Python :: month name in python 
Python :: how to make chrome extension in python 
Python :: sum two columns pandas 
Python :: how to find unique values in list in python 
Python :: numpy declare arraylength 
Python :: how to select rows with specific values in pandas 
Python :: how to replace a word in text file using python 
Python :: cli args python 
Python :: how to make variable global in python 
Python :: make poetry env 
Python :: regex name extract 
Python :: python3 lowercase 
Python :: remove prefix from string python 
Python :: django queryset exists 
Python :: python using random module 
Python :: copy content from one file to another in python 
Python :: querydict instance is immutable 
Python :: how to open a dataset in netcdf4 
Python :: xpath starts-with and ends-with 
Python :: How to read PDF from link in Python] 
Python :: os file size python 
Python :: ModuleNotFoundError: No module named 
Python :: python argv 
Python :: how to clear the list in python 
Python :: tqdm in place 
Python :: python jwt 
Python :: Python Selenium import WebElement 
Python :: PY | websocket - server 
Python :: diamond shape in python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =