Group By

Group By

df.groupby('colName1').colName2.function()
# groups by colName1
# colName2 is the measurement we are evaluating
# returns an array (actually an object) with true function values

df.groupby('colName1').colName2.function().reset_index()
# turns it into a table

df.groupby('colName1').colName2.apply(lambdaFunction()).reset_index()
# for home made functions

df.groupby(['colName1', 'colName2']).colName3.function()
# does every combination of colName1 and colName2

Pivot Tables

The idea of reorganising a table

df.pivot(columns='ColumnToPivot',
         index='ColumnToBeRows',
         values='ColumnToBeValues')

# can follow up with .reset_index()