工作时间以外的掩码时间序列

Mask timeseries outside business hours(工作时间以外的掩码时间序列)
本文介绍了工作时间以外的掩码时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

您好,如果时间序列索引在工作时间之外,我想屏蔽一个每小时时间序列.

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).

这篇关于工作时间以外的掩码时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)