Pandas: Check if a day is a business day (weekday) or not
14. Business Day Check
Write a Pandas program to check if a day is a business day (weekday) or not.
Sample Solution:
Python Code :
import pandas as pd
def is_business_day(date):
return bool(len(pd.bdate_range(date, date)))
print("Check busines day or not?")
print('2020-12-01: ',is_business_day('2020-12-01'))
print('2020-12-06: ',is_business_day('2020-12-06'))
print('2020-12-07: ',is_business_day('2020-12-07'))
print('2020-12-08: ',is_business_day('2020-12-08'))
Sample Output:
Check busines day or not? 2020-12-01: True 2020-12-06: False 2020-12-07: True 2020-12-08: True
For more Practice: Solve these Related Problems:
- Write a Pandas program to check whether given dates are business days using the BDay offset and then output the results.
- Write a Pandas program to filter a date range to include only business days and count the total number of entries.
- Write a Pandas program to create a series of dates, flagging each as business or non-business day based on custom criteria.
- Write a Pandas program to check a list of dates against a holiday calendar and filter out non-business days.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to create a series of Timestamps from a DataFrame of integer or string columns. Also create a series of Timestamps using specified columns.
Next: Write a Pandas program to get a time series with the last working days of each month of a specific year.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.