Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly idiosyncratic usage of groupby #16

Open
dhirschfeld opened this issue Jun 3, 2019 · 2 comments
Open

Slightly idiosyncratic usage of groupby #16

dhirschfeld opened this issue Jun 3, 2019 · 2 comments

Comments

@dhirschfeld
Copy link

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

@chris1610
Copy link
Owner

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

I'll update the notebook and article shortly.

Thank you for the feedback.

@dhirschfeld
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants