Nima Sayyah
Nima Sayyah

Reputation: 77

groupby datetime year-month only

I need to groupby based on the year & month of the Date column so I have a clearer graph presentation and less sample-size.

 
df.groupby(df2['Date'])['¢/kWh'].mean() 

This has helped me to have less sample size and a better presentation. However I need to further groupby based on the month and year.

enter image description here

Upvotes: 0

Views: 55

Answers (1)

Fariliana Eri
Fariliana Eri

Reputation: 301

Try :

df.groupby(df2['Date'].astype(str).str[0:7])['¢/kWh'].mean() 

Upvotes: 1

Related Questions