python - How to create a pandas.date_range with a frequency of one hour excluding weekends?
问题描述
How to create a pandas.date_range
with a frequency of one hour excluding weekends?
Weekmask
doesn't work with standart frequency '1H'
, or with ps.tseries.offsets.DateOffset(hours=1)
. And ps.offsets.BusinessHour(start='0:00', end='23:00')
doesn't include 23:00.
I'm out of ideas. Please, help. Thanks.
解决方案
I believe you need:
r = pd.date_range('2019-09-12', '2019-09-16', freq='H')
r = r[r.dayofweek < 5]
print (r)
DatetimeIndex(['2019-09-12 00:00:00', '2019-09-12 01:00:00',
'2019-09-12 02:00:00', '2019-09-12 03:00:00',
'2019-09-12 04:00:00', '2019-09-12 05:00:00',
'2019-09-12 06:00:00', '2019-09-12 07:00:00',
'2019-09-12 08:00:00', '2019-09-12 09:00:00',
'2019-09-12 10:00:00', '2019-09-12 11:00:00',
'2019-09-12 12:00:00', '2019-09-12 13:00:00',
'2019-09-12 14:00:00', '2019-09-12 15:00:00',
'2019-09-12 16:00:00', '2019-09-12 17:00:00',
'2019-09-12 18:00:00', '2019-09-12 19:00:00',
'2019-09-12 20:00:00', '2019-09-12 21:00:00',
'2019-09-12 22:00:00', '2019-09-12 23:00:00',
'2019-09-13 00:00:00', '2019-09-13 01:00:00',
'2019-09-13 02:00:00', '2019-09-13 03:00:00',
'2019-09-13 04:00:00', '2019-09-13 05:00:00',
'2019-09-13 06:00:00', '2019-09-13 07:00:00',
'2019-09-13 08:00:00', '2019-09-13 09:00:00',
'2019-09-13 10:00:00', '2019-09-13 11:00:00',
'2019-09-13 12:00:00', '2019-09-13 13:00:00',
'2019-09-13 14:00:00', '2019-09-13 15:00:00',
'2019-09-13 16:00:00', '2019-09-13 17:00:00',
'2019-09-13 18:00:00', '2019-09-13 19:00:00',
'2019-09-13 20:00:00', '2019-09-13 21:00:00',
'2019-09-13 22:00:00', '2019-09-13 23:00:00',
'2019-09-16 00:00:00'],
dtype='datetime64[ns]', freq=None)
推荐阅读
- java - 如何使用 Zuul 代理为每个路由或每个端点配置 Ribbon/Hystrix
- html - 如何为屏幕阅读器表达多个价格?
- c# - 手动更新已签名的 ClickOnce 应用程序会引发 TrustNotGrantedException
- python - 列表依赖项列表以及如何打破它 - Python
- c# - 如何知道我的控制台解决方案是否实时向我的数据库插入数据?使用日志?
- r - 如何保存由 varImpPlot 函数生成的图(随机森林)
- javascript - 单击时,如果有课程则提醒,否则添加课程问题
- ios - 如何在swift中为数组内的字典制作模型类?
- apache-flink - 下沉到Destination后的流程元素
- c++ - 使用 Visual Studio 2015 x64 和 CMake 构建 TBB