The Pandas tseries offsets SemiMonthEnd property day_of_month used to retrieve the day of the month for the SemiMonthEnd object. It returns a number that represents the day of the month. If not specified, the default value will be 15.
1 SemiMonthEnd.day_of_month
1 import pandas as pd
2
3
4 offset = pd.tseries.offsets.SemiMonthEnd()
5 res = offset.day_of_month
6 print(f'The day of month for SemiMonthEnd : {res}')
7
8
9 offset1 = pd.tseries.offsets.SemiMonthEnd(day_of_month = 20)
10 res1 = offset1.day_of_month
11 print(f'The day of month for SemiMonthEnd : {res1}')
In the above example, a SemiMonthEnd object is created with and without day_of_month parameter. A day_of_month property is access that returns a number that represents the semi day of the month. The result is assign to the variable that will be printed on console.
1 The day of month for SemiMonthEnd : 15
2 The day of month for SemiMonthEnd : 20
SemiMonthEnd with timestamp and day_of_month
SemiMonthEnd with timestamp and day_of_month
1 import pandas as pd
2
3
4 tstamp = pd.Timestamp(2022, 2, 18)
5 offset = pd.tseries.offsets.SemiMonthEnd()
6 res = tstamp + offset
7 print(f'The resulting timestamp : {res}')
8
9 tstamp1 = pd.Timestamp(2022, 2, 18)
10 offset1 = pd.tseries.offsets.SemiMonthEnd(day_of_month = 20)
11 res1 = tstamp1 + offset1
12 print(f'The resulting timestamp : {res1}')
In the above example, a SemiMonthEnd objects are created with and without the day_of_month month parameter. An offset is added to the timestamp that create timestamp at month end based on SemiMonthEnd object day of the month.
1 The resulting timestamp : 2022-02-28 00:00:00
2 The resulting timestamp : 2022-02-20 00:00:00
Example 2
1 import pandas as pd
2
3 tstamp = pd.Timestamp(2022, 3, 17, 15, 30)
4 print('The timestamp object :', tstamp)
5
6 offset = pd.tseries.offsets.SemiMonthEnd(day_of_month = 20,
7 normalize = True)
8 res = tstamp + offset
9 print(f'The resulting timestamp : {res}')
In the above example, a SemiMonthEnd objects are created with and with the day_of_month month parameter and normalize as true. An offset is added to the timestamp that create timestamp at month end based on SemiMonthEnd object day of the month.
1 The timestamp object : 2022-03-17 15:30:00
2 The resulting timestamp : 2022-03-20 00:00:00
Example 3
1 import pandas as pd
2
3 tstamp1 = pd.Timestamp(2022, 3, 12, 15, 30)
4 print('The timestamp object :', tstamp1)
5
6 offset1 = pd.tseries.offsets.SemiMonthEnd(day_of_month = 20,
7 n = 3, normalize = True)
8 res = tstamp + offset
9 print(f'The resulting timestamp : {res}')
In the above example, a SemiMonthEnd objects are created with and with the day_of_month month parameter and normalize as true with unit frequency as 3. An offset is added to the timestamp that create timestamp at month end based on SemiMonthEnd object day of the month.
1 The timestamp object : 2022-03-12 15:30:00
2 The resulting timestamp : 2022-03-20 00:00:00
Related options for your search