简体   繁体   中英

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.

在此处输入图像描述

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM