Pandas tseries offsets FY5253Quarter function rollback() in Python
The Pandas tseries offsets FY5253Quarter function rollback() rolls specified date backward to next offset only if no on offset. It returns a rolled timestamp if not on offset, otherwise unchanged timestamp.
Syntax
 1 FY5253Quarter.rollback()
rollback() function
 1 import pandas as pd
 2 
 3 offset = pd.tseries.offsets.FY5253Quarter()
 4 
 5 tstamp = pd.Timestamp(2022, 4, 1)
 6 res = offset.rollback(tstamp)
 7 print(f'The rolled backward timestamp : {res}')
 8 
 9 tstamp1 = pd.Timestamp(2022, 1, 31)
 10 res1 = offset.rollback(tstamp1) # unchanged timestamp
 11 print(f'The rolled backward timestamp : {res1}')
In the above example, a Timestamp objects are created with date value. A rollback() function is called that rolls back timestamp to the next offset. The result is assign to the variable that will be printed on console.
Output
 1 The rolled backward timestamp : 2022-01-31 00:00:00
 2 # an unchanged timestamp
 3 The rolled backward timestamp : 2022-01-31 00:00:00

Example 2

Example 2
 1 import pandas as pd
 2 
 3 tstamp = pd.Timestamp(2023, 1, 31)
 4 print('The timestamp object :', tstamp)
 5 
 6 offset = pd.tseries.offsets.FY5253Quarter(normalize = True)
 7 res = offset.rollback(tstamp)
 8 print(f'The rolled backward timestamp : {res}')
In the above example, a Timestamp objects are created with date value and FY5253Quarter with normalize as true. A rollback() function is called that rolls back timestamp to the next offset.
Output
 1 The timestamp object : 2023-01-31 00:00:00
 2 The rolled backward timestamp : 2023-01-30 00:00:00

Example 3

Example 3
 1 import pandas as pd
 2 
 3 tstamp1 = pd.Timestamp(2024, 1, 31)
 4 print('The timestamp object :', tstamp1)
 5 
 6 offset1 = pd.tseries.offsets.FY5253Quarter(n = 3, weekday = 4, normalize = True)
 7 res1 = offset1.rollback(tstamp1)
 8 print(f'The rolled backward timestamp : {res1}')
In the above example, a Timestamp objects are created with date value and FY5253Quarter with unit frequency as 3, weekday as 4 and normalize as true. A rollback() function is called that rolls back timestamp to the next offset.
Output
 1 The timestamp object : 2024-01-31 00:00:00
 2 The rolled backward timestamp : 2023-11-03 00:00:00
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us