2017-10-09 144 views
2

我有日期时间为指标和一些数据,这样的数据帧:如何在pandas的数据框中编制索引时间段?

date_index = pd.date_range('2015-12-01 00:00:00', freq='1H', periods=50) 
df = pd.DataFrame(np.random.rand(50), index= date_index, columns=['Data']) 

我想只有从时间间隔06:00选择数据00:00所有的日子。我怎样才能做到这一点?

我在考虑使用类似df.at_time('6am')的东西,但这只返回此特定小时的数据帧,而不是来自间隔。

我是熊猫新手,我无法找到如何做到这一点。

谢谢!

回答

3

使用between_time

df.between_time('6:00:00', '23:59:59') 

df.between_time('6:00:00', '23:59:59').index.hour.unique() 
#Int64Index([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 
#   23], 
#   dtype='int64') 
相关问题