Pandas tseries offsets MonthBegin function is_year_end() in Python
The Pandas tseries offsets MonthBegin function is_year_end() used to determine whether a timestamp occurs on the year end. It returns a boolean value that determines whether timestamp occurs at the end of the year.
Syntax
 1 MonthBegin.is_year_end()
is_year_end() function
 1 import pandas as pd
 2 
 3 offset = pd.offsets.MonthBegin(n = 2)
 4 
 5 tstamp = pd.Timestamp(2022, 11, 30)
 6 res = offset.is_year_end(tstamp)
 7 print(f'Does timestamp occurs at month end of year : {res}')
 8 
 9 tstamp1 = pd.Timestamp(2022, 12, 31)
 10 res1 = offset.is_year_end(tstamp1)
 11 print(f'Does timestamp occurs at month end of year : {res1}')
In the above example, a MonthBegin object is created by passing a n frequency unit. A Timestamp objects are created by passing a end of the year and second object is not at end of the year. A is_year_end() function is called that determine whether the timestamp occurs at the end of the year. The result is assign to the variable that will be printed on console.
Output
 1 Does timestamp occurs at end of year : True
 2 Does timestamp occurs at end of year : False

Example 2

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

Example 3

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