从 pandas 数据框中删除非营业日行 [英] Remove non-business days rows from pandas dataframe

查看:76
本文介绍了从 pandas 数据框中删除非营业日行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据帧,其中包含df中小麦的第二时间序列数据.

I have a dataframe with second timeseries data of wheat in df.

df = wt["WHEAT_USD"]

2016-05-02 02:00:00+02:00    4.780
2016-05-02 02:01:00+02:00    4.777
2016-05-02 02:02:00+02:00    4.780
2016-05-02 02:03:00+02:00    4.780
2016-05-02 02:04:00+02:00    4.780
Name: closeAsk, dtype: float64

当我绘制数据时,由于周末,这些数据具有令人讨厌的水平线.是否有任何简单的方法可以简单地从数据框本身中删除非工作日.

When I plot the data it has theese annoying horizontal lines because of weekends. Are there any simple way of simply removing the non-business days from the dataframe itself.

类似

df = df.BDays()

推荐答案

一种简单的解决方案是将星期一至星期五以外的日子切成片:

One simple solution is to slice out the days not in Monday to Friday:

In [11]: s[s.index.dayofweek < 5]
Out[11]:
2016-05-02 00:00:00    4.780
2016-05-02 00:01:00    4.777
2016-05-02 00:02:00    4.780
2016-05-02 00:03:00    4.780
2016-05-02 00:04:00    4.780
Name: closeAsk, dtype: float64

注意:这不考虑银行假期等.

这篇关于从 pandas 数据框中删除非营业日行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆