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

Example 2

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

Example 3

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