Skip to content

Slightly idiosyncratic usage of groupby #16

Description

@dhirschfeld

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions