I have a list of sales products, and I would like to group the sales by product by month. I am using a dataframe, which index is a time index, and have a column product.
I tried :
df.groupby(['product', pd.TimeGrouper(freq='1M')])['sales'].sum()
but it give an error : 'TimeGrouper' object is not callable
I also tried
df.groupby(pd.TimeGrouper(freq='1M')).groupby('sales').sum()
but it gives an error : cannot access callable atttribute 'groupby' of 'dataframegroupby' objects.
Any ideas ?
PS : I can't copy paste code from my work to internet.
This worked for me. I'm not sure why you're getting the TypeError...
df.groupby(['product', pd.TimeGrouper('1M')])['sales'].sum()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With