To perform regular differncing,seasonal adjustment and log transformatio on settle weather data
- Import the required packages like pandas and numpy
- Read the data using the pandas
- Perform the data preprocessing if needed and apply regular differncing,seasonal adjustment,log transformation.
- Plot the data according to need, before and after regular differncing,seasonal adjustment,log transformation.
- Display the overall results.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.stattools import adfuller, kpss
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
data = pd.read_csv('/content/seattle_weather_1948-2017.csv', parse_dates=['DATE'], index_col='DATE')
def test_stationarity(series):
result = adfuller(series.dropna())
print('ADF Statistic:', result[0])
print('p-value:', result[1])
print('Critical Values:', result[4])
print('')
test_stationarity(data['PRCP'])
plt.figure(figsize=(10, 6))
plt.plot(data['PRCP'], label='PRCP')
plt.title('Precipitation Over Time')
plt.xlabel('Date')
plt.ylabel('Precipitation')
plt.legend()
plt.show()
data['PRCP_diff'] = data['PRCP'] - data['PRCP'].shift(1)
data_diff = data.dropna()
test_stationarity(data_diff['PRCP_diff'])
plt.figure(figsize=(10, 6))
plt.plot(data_diff['PRCP_diff'], label='Differenced PRCP')
plt.title('Differenced Precipitation Over Time')
plt.xlabel('Date')
plt.ylabel('Differenced Precipitation')
plt.legend()
plt.show()
plt.figure(figsize=(12, 6))
plt.subplot(121)
plot_acf(data_diff['PRCP_diff'], ax=plt.gca(), lags=40)
plt.title('ACF of Differenced PRCP')
plt.subplot(122)
plot_pacf(data_diff['PRCP_diff'], ax=plt.gca(), lags=40)
plt.title('PACF of Differenced PRCP')
plt.tight_layout()
plt.show()
Thus we have created the python code for the conversion of non stationary to stationary data on settle weather data.



