3

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 !

0

2 Answers 2

5

Use apply with parameetr axis=1 for process by rows:

df['count_holiday_and_weekends'] = df.apply(lambda x: count_holiday_and_weekends(x['fromdate'],x['todate']), axis=1)
Sign up to request clarification or add additional context in comments.

Comments

0

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.