Ad
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.
Ad
Answer
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)
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad