chris1610 / pbpython

Code, Notebooks and Examples from Practical Business Python
https://pbpython.com
BSD 3-Clause "New" or "Revised" License
1.99k stars 987 forks source link

Slightly idiosyncratic usage of groupby #16

Open dhirschfeld opened 5 years ago

dhirschfeld commented 5 years ago

When grouping by month in the notebook below you use a pd.Grouper object: https://github.com/chris1610/pbpython/blob/d170f4475720ca8f5fdc6770214b8f90f2197f75/notebooks/pandas-styling.ipynb#L733-L735

..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

chris1610 commented 5 years ago

Thanks for the feedback. It's a good point.

I'll update the notebook and article shortly.

Thank you for the feedback.

dhirschfeld commented 5 years ago

It's a great article! I'm planning on sharing it with my users, most of whom are just learning Python.