When grouping by month in the notebook below you use a pd.Grouper object:
|
"monthly_sales = df.groupby([pd.Grouper(key='date', freq='M')])['ext price'].agg(['sum']).reset_index()\n", |
|
"monthly_sales['pct_of_total'] = monthly_sales['sum'] / df['ext price'].sum()\n", |
|
"monthly_sales" |
..whereas the same could be accomplished by simply using the resample method:
monthly_sales = df.resample('MS', on='date')['ext price'].agg(['sum'])
Whilst I think it's useful for power users to know they can construct Grouper objects themselves I think for less advanced users it's an internal implementation detail which they don't really need to know and which makes it seem more complicated than it needs to be
When grouping by month in the notebook below you use a
pd.Grouperobject:pbpython/notebooks/pandas-styling.ipynb
Lines 733 to 735 in d170f44
..whereas the same could be accomplished by simply using the
resamplemethod:Whilst I think it's useful for power users to know they can construct
Grouperobjects themselves I think for less advanced users it's an internal implementation detail which they don't really need to know and which makes it seem more complicated than it needs to be