The Pandas tseries offsets QuarterBegin function is_month_end() used to determine whether the timestamp occurs on the month end. It returns a boolean value that specifies whether the timestamp occurs at the end of quarter month.
1 QuarterBegin.is_month_end()
1 import pandas as pd
2
3 offset = pd.tseries.offsets.QuarterBegin()
4
5 tstamp = pd.Timestamp(2022, 6, 30)
6 res = offset.is_month_end(tstamp)
7 print(f'Timestamp at quarter month end :{res}')
8
9 tstamp1 = pd.Timestamp(2022, 5, 30)
10 res1 = offset.is_month_end(tstamp1)
11 print(f'Timestamp at quarter month end :{res1}')
In the above example, a Timestamp created by passing a date value. A is_month_end() function is called that determine whether a timestamp occurs at the end of quarter month. The result is assign to the variable that will be printed on console.
1 Timestamp at quarter month end :True
2 Timestamp at quarter month end :False
Example 2
1 import pandas as pd
2
3 tstamp = pd.Timestamp(2023, 4, 30)
4 print('The timestamp object :', tstamp)
5
6 offset = pd.tseries.offsets.QuarterBegin(normalize = True)
7 res = offset.is_month_end(tstamp)
8 print(f'Timestamp at quarter month end :{res}')
In the above example, a Timestamp created by passing a date value and QuarterBegin object with normalize as true. A is_month_end() function is called that determine whether a timestamp occurs at the end of quarter month.
1 The timestamp object : 2023-04-30 00:00:00
2 Timestamp at quarter month end :True
Example 3
1 import pandas as pd
2
3 tstamp1 = pd.Timestamp(2024, 5, 31)
4 print('The timestamp object :', tstamp1)
5
6 offset1 = pd.tseries.offsets.QuarterBegin(n = 3, startingMonth = 4, normalize = True)
7 res1 = offset1.is_month_end(tstamp1)
8 print(f'Timestamp at quarter month end :{res}')
In the above example, a Timestamp created by passing a date value and QuarterBegin object with normalize as true, unit frequency as 3 and startingMonth as 4. A is_month_end() function is called that determine whether a timestamp occurs at the end of quarter month.
1 The timestamp object : 2024-05-31 00:00:00
2 Timestamp at quarter month end :True
Related options for your search