【问题标题】:Date Quarters in 'Series' object python“系列”对象python中的日期季度
【发布时间】:2019-02-23 06:40:00
【问题描述】:

我正在尝试计算每个日期的值,以计算女巫季度的频率很高我尝试这些方法到目前为止不起作用...请帮助 :) 谢谢。 注意:时间是'系列'对象

stime=df['timestamp']
#print (df['timestamp'].filter(like='08', axis=0)
#stime.filter(like='2018-07-18')
#stime.between_date('2018-01-01','2018-02-01', include_start=True, include_end=True)
#stime.month

【问题讨论】:

标签: python-3.x pandas series


【解决方案1】:

试试这个:

data = pd.DataFrame({'timestamp': ['2018-01-07', '2018-01-08', '2018-04-08',
                                  '2018-03-09', '2018-09-08', '2018-12-08',
                                  '2018-01-21', '2018-09-11', '2018-03-08',
                                  '2018-11-08', '2018-10-18', '2018-04-04']})
data.timestamp = pd.to_datetime(data.timestamp)
data['quarter'] = data.timestamp.dt.quarter
data['month'] = data.timestamp.dt.month

data.groupby(['quarter', 'month']).month.count()

我希望它有所帮助。如果你也想按年计算,你可以添加data['year'] = data.timestamp.dt.yeardata.groupby(['quarter', 'month', 'year']).month.count()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    • 2021-10-28
    • 1970-01-01
    相关资源
    最近更新 更多