Remove business days rows from pandas dataframe

I have a data frame with second wheat temporary data 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 draw the data, it has its annoying horizontal lines due to the weekend. Is there an easy way to simply remove non-working days from the data file itself.

Something like

 df = df.BDays() 
+7
python pandas
source share
2 answers

One simple solution is to cut non-Monday through Friday days:

 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 

Note: this does not include holidays, etc.

+14
source share

Pandas BDay just ends up using .dayofweek<5 as the selected answer, but can be expanded to account for holidays, etc.

 import pandas as pd from pandas.tseries.offsets import BDay isBusinessDay = BDay().onOffset csv_path = 'C:\\Python27\\Lib\\site-packages\\bokeh\\sampledata\\daylight_warsaw_2013.csv' dates_df = pd.read_csv(csv_path) match_series = pd.to_datetime(dates_df['Date']).map(isBusinessDay) dates_df[match_series] 
+3
source share

All Articles