Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Group multiple columns in pandas

import pandas as pd

# Group multiple columns and get statistics
df = df.groupby(["store", "type"])["weekly_sales"].sum()

# Group multiple columns and multiple statistics
df = df.groupby(["store", "type"])["weekly_sales"].agg([sum, min, max])

# Display DataFrame
print(df)
Source by pandas.pydata.org #
 
PREVIOUS NEXT
Tagged: #Group #multiple #columns #pandas
ADD COMMENT
Topic
Name
3+3 =