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