Pandas: Calculate one business day from a specified date
27. Calculate Business Days and Month End
Write a Pandas program to calculate one, two, three business day(s) from a specified date. Also find the next business month end from a specific date.
Sample Solution:
Python Code :
import pandas as pd
from pandas.tseries.offsets import *
import datetime
from datetime import datetime, date
dt = datetime(2020, 1, 4)
print("Specified date:")
print(dt)
print("\nOne business day from the said date:")
obday = dt + BusinessDay()
print(obday)
print("\nTwo business days from the said date:")
tbday = dt + 2 * BusinessDay()
print(tbday)
print("\nThree business days from the said date:")
thbday = dt + 3 * BusinessDay()
print(thbday)
print("\nNext business month end from the said date:")
nbday = dt + BMonthEnd()
print(nbday)
Sample Output:
Specified date: 2020-01-04 00:00:00 One business day from the said date: 2020-01-06 00:00:00 Two business days from the said date: 2020-01-07 00:00:00 Three business days from the said date: 2020-01-08 00:00:00 Next business month end from the said date: 2020-01-31 00:00:00
For more Practice: Solve these Related Problems:
- Write a Pandas program to calculate one, two, and three business days from a specified date and then determine the next month-end date.
- Write a Pandas program to generate a series of business day offsets from a base date and then identify the subsequent month-end.
- Write a Pandas program to compute the next business month-end for a given date using custom holiday rules and verify the result.
- Write a Pandas program to calculate business day increments from a specified date and then find the corresponding next month-end date.
Go to:
Previous: Write a Pandas program to convert integer or float epoch times to Timestamp and DatetimeIndex.
Next: Write a Pandas program to create a period index represent all monthly boundaries of a given year. Also print start and end time for each period object in the said index.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.