0

I have the dataset of sales of cars in various cities in which I want to divide the dataset into city-wise quarter sales I tried the code but it didn't work.

qu=df.groupby([(df.City),(df.index.year),(df.quarter)]).agg(['sum', 'count'])

1 Answers1

0

Try something like

df['year'] = df.index.dt.year # Based on your index name
df.groupby(by=['City','year','quarter']).agg(['sum','count'])
Literal
  • 757
  • 6
  • 16