Reputation:
I have a simple function that counts weekends and holidays within two dates in python...
count_holiday_and_weekends(fromdate,todate)
How do i apply the function to create a new one in my df ?
Something like:
df['count_holiday_and_weekends'] = count_holiday_and_weekends(df['fromdate'],df['todate])
thanks in advance !
Upvotes: 3
Views: 419
Reputation: 323226
If you know which columns to be used in the function you can do
df.assign(count_holiday_and_weekends=df[['fromdate','todate']].apply(count_holiday_and_weekends,axis=1))
Upvotes: 0