I am trying to remove seasonality and trends from my time series data. I found this post that said to use df_diff = df.diff().diff(12).dropna() (https://www.tobiolabode.com/blog/2020/12/30/how-to-convert-non-stationary-data-into-stationary-for-arima-model-with-python). I don't understand why we need to use diff(12) from pandas. Could someone explain this to me? Thanks!
Since the data is recorded every month (i.e. a data point for each month in the year) and we see a yearly seasonality trend we compare the data for the same month against previous year. This is done by taking the difference against the data from last year (
.diff()), which is equal to going back 12 observations since each observation is data for a specific month.