您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

pandas,python-如何选择时间序列中的特定时间

pandas,python-如何选择时间序列中的特定时间

这是一个满足您需求的示例:

In [32]: from datetime import datetime as dt

In [33]: dr = p.DateRange(dt(2009,1,1),dt(2010,12,31), offset=p.datetools.Hour())

In [34]: hr = dr.map(lambda x: x.hour)

In [35]: dt = p.DataFrame(rand(len(dr),2), dr)

In [36]: dt

Out[36]: 
<class 'pandas.core.frame.DataFrame'>
DateRange: 17497 entries, 2009-01-01 00:00:00 to 2010-12-31 00:00:00
offset: <1 Hour>
Data columns:
0    17497  non-null values
1    17497  non-null values
dtypes: float64(2)

In [37]: dt[(hr >= 10) & (hr <=16)]

Out[37]: 
<class 'pandas.core.frame.DataFrame'>
Index: 5103 entries, 2009-01-01 10:00:00 to 2010-12-30 16:00:00
Data columns:
0    5103  non-null values
1    5103  non-null values
dtypes: float64(2)
python 2022/1/1 18:43:17 有292人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶