在营业时间之外屏蔽时间序列

编程入门 行业动态 更新时间:2024-10-26 22:26:01
本文介绍了在营业时间之外屏蔽时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,我有一个小时时间序列,如果时间序列索引不在工作时间,我想掩盖.

Hello I have an hourly timeseries that I would like to mask if the timeseries index is outside business hours.

我可以实现我想要的工作日数据,而不是每小时数据

I can achieve what I want for business day data but not hourly data

import datetime import pandas as pd import numpy as np from pandas.tseries.offsets import * st = datetime.datetime(2013, 1, 1) ed = datetime.datetime(2013, 2, 1) myrange = pd.date_range(st, ed, freq='H') ts = pd.Series(np.random.randn(len(myrange)), index=myrange) ts.asfreq(BDay()).asfreq(Day())

我尝试生成BDay日期范围,然后将频率更改为每小时,但这不起作用.

I have tried generating a BDay date range and then changing the freq to hourly but this doesn't work.

newrange = pd.date_range(datetime.datetime(2013, 1, 1), datetime.datetime(2013, 1, 1), freq='B') #but adding this doesn't work .asfreq(Hour()) ts[ts.index.isin(newrange)].asfreq(Hour()) #Of course this only gives one value on the day

谢谢

推荐答案

要将时间限制为工作日,可以使用:

To restrict your times to Business days you could use:

ts = ts.ix[ts.index.map(BDay())]

和 indexer_between_time 来限制营业时间:

and indexer_between_time to restrict between business hours:

ts = ts.ix[ts.index.indexer_between_time(time(7), time(18))]

要限制在工作时间内的工作日(以任何一种顺序应用).

To restrict to Business days within business hours (apply these in either order).

更多推荐

在营业时间之外屏蔽时间序列

本文发布于:2023-10-23 01:39:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519359.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   屏蔽   营业时间   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!