I have a data set that i needs column y data to be offset by n number of dates later. For example on the screenshot below, reference date for 22nd April should be offset by data in columns X 3 days later.

If want shift each 3 days:
df.index = pd.to_datetime(df.index, format='%d-%b')
df['Y'] = df['X'].shift(-3, freq='d')
If want shift each 3 rows:
df['Y'] = df['X'].shift(-3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With