User Tools

Site Tools


aggregations

Multiple Aggregations

The aggregation functionality provided by the agg() function allows multiple statistics to be calculated per group in one calculation. The syntax is simple, and is similar to that of MongoDB’s aggregation framework.

# Define the aggregation procedure outside of the groupby operation
# In the dictionary you must put the actual name of the column of the df NOT the name of the function
 
aggregations = {
    'duration':'sum',
    'date': lambda x: max(x)
}
 
data.groupby('month').agg(aggregations)

Count

Group-by a reference (ie. day) and count the occurrencies. Store it into a dataframe.

df.groupby('date').size().to_frame().reset_index()
aggregations.txt · Last modified: 2017/01/05 14:24 by vincenzo