我与时区的日期时间索引不同。我想从中提取分钟和小时吗?怎么
我的代码:
df.index = DatetimeIndex(['2015-01-01 09:50:00-05:00', '2015-01-01 10:08:00-05:00',
'2015-01-01 10:13:00-05:00', '2015-01-01 10:18:00-05:00',
'2015-01-01 10:23:00-05:00', '2015-01-01 10:28:00-05:00',
'2015-01-01 10:33:00-05:00', '2015-01-01 10:38:00-05:00',
'2015-01-01 10:43:00-05:00', '2015-01-01 10:48:00-05:00',
...
'2016-01-31 16:27:00-05:00', '2016-01-31 16:32:00-05:00',
'2016-01-31 16:37:00-05:00', '2016-01-31 16:42:00-05:00',
'2016-01-31 16:47:00-05:00', '2016-01-31 16:52:00-05:00',
'2016-01-31 16:57:00-05:00', '2016-01-31 17:02:00-05:00',
'2016-01-31 17:07:00-05:00', '2016-01-31 17:12:00-05:00'],
dtype='datetime64[ns, pytz.FixedOffset(-300)]', name='TIMESTAMP', length=275533, freq=None)
print(df.index.date.hour)
输出:
AttributeError: 'numpy.ndarray' object has no attribute 'hour'
答案 0 :(得分:0)
您需要使用dt
来访问诸如hour
或day
之类的属性。
df.index.to_series().dt.hour