The Pandas tseries offsets class BusinessDay is a subclass of DateOffset that represent n (number) possible business day.
1 class pandas.tseries.offsets.BusinessDay
n : It is an integer that specifies the number of days. If not specified the default value will be 1.
normalize : It is boolean that specifies whether to normalize start or end dates to midnight. If not specified the default value will be False.
offset : It is timedelta that specifies the time offset to apply. If not specified the default value will be timedelta(0).
1 import pandas as pd
2
3 tstamp = pd.Timestamp(2022, 5, 25, 15)
4 res = tstamp.strftime('%a %d %b %Y %H:%M')
5 print('The formatted timestamp :')
6 print(res)
7
8 bday = pd.offsets.BusinessDay(n = 5)
9 res1 = tstamp + bday
10 print('The resulting business day :')
11 print(res1.strftime('%a %d %b %Y %H:%M'))
In the above example, a Timestamp object is created by passing a values. A Timestamp object is formatted using strftime() function. A BusinessDay object is created by passing a number of days and added to the timestamp object that created Timestamp object that assign to the variable that will be printed on console.
1 The formatted timestamp :
2 Wed 25 May 2022 15:00
3
4 The resulting business day :
5 Wed 01 Jun 2022 15:00
BusinessDay with normalize
BusinessDay with normalize
1 import pandas as pd
2
3 tstamp = pd.Timestamp(2022, 5, 25, 15)
4 res = tstamp.strftime('%a %d %b %Y %H:%M')
5 print('The formatted timestamp :')
6 print(res)
7
8 bday = pd.offsets.BusinessDay(n = 5, normalize = True)
9 res1 = tstamp + bday
10 print('The resulting business day :')
11 print(res1.strftime('%a %d %b %Y %H:%M'))
In the above example, a BusinessDay object is created by passing a number of business day and normalize parameters that creates timestamp that shift the start of the next business day to midnight.
1 The formatted timestamp :
2 Wed 25 May 2022 15:00
3
4 The resulting business day :
5 Wed 01 Jun 2022 00:00
BusinessDay with negative days
BusinessDay with negative days
1 import pandas as pd
2
3 tstamp = pd.Timestamp(2022, 5, 25, 15)
4 res = tstamp.strftime('%a %d %b %Y %H:%M')
5 print('The formatted timestamp :')
6 print(res)
7
8 bday = pd.offsets.BusinessDay(n = -2, normalize = True)
9 res1 = tstamp + bday
10 print('The resulting business day :')
11 print(res1.strftime('%a %d %b %Y %H:%M'))
In the above example, a BusinessDay object is created by passing a n value as negative value that added to the timestamp object. It reduce two business days from the timestamp.
1 The formatted timestamp :
2 Wed 25 May 2022 15:00
3
4 The resulting business day :
5
6 Mon 23 May 2022 00:00
Related options for your search