Pandas tseries offsets SemiMonthBegin function is_year_end() in Python
The Pandas tseries offsets SemiMonthBegin function is_year_end() used to determine whether a timestamp occurs on the year end. It returns a boolean value that specifies whether the timestamp occurs at the end of the year.
Syntax
 1 SemiMonthBegin.is_year_end()
dt : It is Timestamp to determine whether the timestamp is at end of year. It is an instance of datetime.datetime.
is_year_end() function
 1 import pandas as pd
 2 
 3 offset = pd.tseries.offsets.SemiMonthBegin()
 4 
 5 # timestamp at year end - does next offset at year end
 6 tstamp = pd.Timestamp(2022, 11, 30)
 7 res = offset.is_year_end(tstamp)
 8 print(f'Does next offset at end of year : {res}')
 9 
 10 # timestamp not at end of year
 11 tstamp2 = pd.Timestamp(2022, 11, 20)
 12 res2 = offset.is_year_end(tstamp2)
 13 print(f'Does next offset at end of year : {res2}')
In the above example, a Timestamp objects are created by passing a date that is at a end of the month and second is not at the end of the month. An is_year_end() function is called that determine whether the next offset at year end. The result is assign to the variable that will be printed on console.
Output
 1 Does next offset at end of year : True
 2 Does next offset at end of year : False

Example 2

Example 2
 1 import pandas as pd
 2 
 3 tstamp = pd.Timestamp(2022, 11, 30)
 4 print('The timestamp object :', tstamp)
 5 
 6 offset = pd.tseries.offsets.SemiMonthBegin(normalize = True)
 7 res = offset.is_year_end(tstamp)
 8 print(f'Does next offset at end of year : {res}')
In the above example, a Timestamp objects are created by passing a date that is at a end of the month and a SemiMonthBegin with normalize as true. An is_year_end() function is called that determine whether the next offset at year end.
Output
 1 The timestamp object : 2022-11-30 00:00:00
 2 Does next offset at end of year : True

Example 3

Example 3
 1 import pandas as pd
 2 
 3 tstamp1 = pd.Timestamp(2022, 12, 31)
 4 print('The timestamp object :', tstamp1)
 5 
 6 offset1 = pd.tseries.offsets.SemiMonthBegin(n = 3, normalize = True)
 7 res1 = offset1.is_year_end(tstamp1)
 8 print(f'Does next offset at end of year : {res1}')
In the above example, a Timestamp objects are created by passing a date that is at a end of the month and a SemiMonthBegin with normalize as true and unit frequency as true. An is_year_end() function is called that determine whether the next offset at year end.
Output
 1 The timestamp object : 2022-12-31 00:00:00
 2 Does next offset at end of year : True
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us