Pandas: Check if a day is a business day (weekday) or not
Pandas Time Series: Exercise-14 with Solution
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
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/pandas/time-series/pandas-time-series-exercise-14.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics