Patrick S
Patrick S

Reputation: 57

Removing Non Business Days from Pandas Dataframe

I have a Pandas dataframe with a column containing dates associated with the data. I'm looking to remove all rows of data that are not business days (accounting for bank holidays as well). What are the best ways to accomplish this?

Upvotes: 2

Views: 1556

Answers (1)

BENY
BENY

Reputation: 323226

When we check the holiday we can always create the holiday list then use isin

from pandas.tseries.holiday import USFederalHolidayCalendar as calendar
holidays = calendar.holidays(start='2000-01-01', end='2020-12-31')
m = df['date'].isin(holidays)
df1 = df[~m].copy()

Upvotes: 4

Related Questions