Check If A Date Is A Business Date Within A Pandas Dataframe
I have already checked the business days in python question but wasn't able to figure out how to do the following problem. I want to check whether a date is a business date or week
Solution 1:
I think you need to_datetime
+ BDay
from pandas.tseries.offsets import *
df.date=pd.to_datetime(df.date)# convert your datetime into pandas
df['New']=np.where(df.date.dt.weekday_name.isin(['Saturday','Sunday']),df.date+BDay(1),df.date)
df
Out[1118]:
date New
0 2017-11-04 2017-11-06
1 2017-11-08 2017-11-08
2 2017-11-16 2017-11-16
3 2017-11-17 2017-11-17
4 2017-11-19 2017-11-20
5 2017-11-22 2017-11-22
6 2017-11-23 2017-11-23
Post a Comment for "Check If A Date Is A Business Date Within A Pandas Dataframe"