我正在尝试计算每个日期中的值,以便计算女巫季度的频率。我尝试了这些方法,目前为止仍无法正常工作...请帮助:)谢谢。 注意:stime是“系列”对象
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
答案 0 :(得分:0)
尝试一下:
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.year
和data.groupby(['quarter', 'month', 'year']).month.count()