Pandas tseries offsets Week function is_month_end() in Python
The Pandas tseries offsets Week 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 Week.is_month_end()
is_month_end() function
 1 import pandas as pd
 2 
 3 offset = pd.tseries.offsets.Week()
 4 
 5 tstamp = pd.Timestamp(2022, 1, 31)
 6 res = offset.is_month_end(tstamp)
 7 print(f'The Week offset at month end : {res}')
 8 
 9 tstamp1 = pd.Timestamp(2022, 1, 15)
 10 res1 = offset.is_month_end(tstamp1)
 11 print(f'The Week offset at month end : {res1}')
In the above example, a Timestamp objects are created by passing a date value. An is_month_end() is called that determine whether an timestamp occurs at end of month. The result is assign to the variable that will be printed on console.
Output
 1 The Week offset at month end : True
 2 The Week offset at month end : False

Example 2

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

Example 3

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