Reputation: 23
I want to get a weekly mean of data for every year. So I am using groupby
for week and year as in the below code:
hdfc.groupby([hdfc.Date.dt.year,hdfc.Date.dt.week]).mean()
How can I make week and year as the columns of the data? reset_index() is giving me an error "cannot insert Date, already exists" since both the columns have the name Date which is generated by groupby function.
Upvotes: 1
Views: 203
Reputation: 345
Below given piece of code will output your desired result:
df.rename_axis(index=['Year', 'Week']).reset_index()
Upvotes: 1