【问题标题】:Averaging Python Pandas Date format平均 Python Pandas 日期格式
【发布时间】:2018-02-20 15:23:56
【问题描述】:

我有一些类似以下格式的数据:

2016-06-02 22:00:00 
2016-06-02 22:00:01 
2016-06-02 22:00:01 
2016-06-02 22:00:02 
2016-06-02 22:00:02

这些数据在 Pandas DataFrame 中,我想要的是按天平均,如下所示:

2016-06-2  I 300 

所以我想计算一下有多少项目,被这个平均了。

有什么想法吗?我尝试使用 value_counts,但它给出了错误的结果。

【问题讨论】:

    标签: python pandas date time average


    【解决方案1】:

    看来你需要:

    df = df['date'].dt.date.value_counts()
    

    或者:

    df = df.groupby(df['date'].dt.date).size()
    

    【讨论】:

      猜你喜欢
      • 2017-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多