简体   繁体   English

groupby datetime 仅限年月

[英]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.我需要根据 Date 列的年份和月份进行分组,这样我的图形表示更清晰,样本量更少。

 
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() 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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