In this post, you will learn how to calculate business days in Pandas.
Working with data is tedious and difficult for anyone who works with data. I have prepared a code in Python that will make it easier for you to work with working days in a data table in Pandas.
How to get business days between dates in Pandas
You can use the bd_range function to display the working days between two dates in Pandas. Just give two dates as arguments and Pandas will return you a list of working days.
import pandas as pd start_date = '2023-01-01' end_date = '2023-07-01' bd_diff = pd.bdate_range(start_date, end_date) print(bd_diff)
Pandas has prepared a DatetimeIndex list that contains all working days between the dates I provided.
The number of working days between start date and end date is also displayed.
How to calculate business days in Pandas
You can also calculate the number of working days between start date and end date in another way.
Just return the length of the list of working days.
import pandas as pd start_date = '2023-01-01' end_date = '2023-07-01' bd_diff = pd.bdate_range(start_date, end_date) no_of_bd = len(bd_diff) print(no_of_bd)
Pandas printed the number of working days with no redundant data. The number of working days can be used for further calculations or data processing.
See also:
Documentation of bd_range function
Pingback: How To Calculate Percent Change • Pandas How To