I'm working on a time series, it has a index as dates and a values field. I used these 2 lines to difference the data.
df['value2'] = (df['value'] - df.value.rolling(window=12).mean()) / df.value.rolling(window=12).std()
df['value3'] = df['value2'] - df['value2'].shift(12)
This made my dataset stationary, so i'm happy to continue using this.
Now I have ran some analysis from this and now I have values which I'm trying to undifference.
If my result dataset is saved in df_results, how do I make these normal again (undifference them). Is there a way to reverse the transformations?
** SOLUTION **
I figured out a way to reverse the differencing on the dataset.
# DIFFERENCING
df['stp1'] = (df['cpi'] - df.cpi.rolling(window=12).mean())
df['stp2'] = df['stp1'] / df.cpi.rolling(window=12).std()
df['stp3'] = df['stp2'] - df['stp2'].shift(12)
# INVERSE DIFFERENCING
df['stp3r'] = df['stp3'] + df['stp2'].shift(12)
df['stp2r'] = df['stp3r'] * df.cpi.rolling(window=12).std()
df['stp1r'] = (df['stp2r'] + df.cpi.rolling(window=12).mean())
In order to apply this to a forecasted dataset I followed a very similar way. In this the only variable changed is 'wmar' which where the differenced forecast is saved, the last data field 'fcast3' is where the reversed differenced forecast exists:
df['fcast'] = wmar + df['stp2'].shift(12)
df['fcast2'] = df['fcast'] * df.cpi.rolling(window=12).std()
df['fcast3'] = (df['fcast2'] + df.cpi.rolling(window=12).mean())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…