Time Series Visualization
Good visualization is often the fastest way to understand a Time Series - spotting trend, seasonality, and outliers visually before applying any formal model.
Basic Line Plot
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
"Month": pd.date_range(start="2024-01-01", periods=24, freq="M"),
"Sales": [200,220,210,250,270,300,320,310,330,360,400,420,
210,230,225,260,280,310,330,325,345,375,410,430]
})
df.set_index("Month", inplace=True)
df["Sales"].plot(title="Monthly Sales Over Time")
plt.show()
Rolling Average to Smooth Noise
df["RollingMean"] = df["Sales"].rolling(window=3).mean()
df[["Sales", "RollingMean"]].plot(title="Sales vs 3-Month Rolling Average")
plt.show()
Seasonal Decomposition Plot
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(df["Sales"], model="additive", period=12)
result.plot()
plt.show()
What to Look For
A rising or falling line suggests trend, repeating peaks at regular intervals suggest seasonality, and sudden spikes or dips that don't fit the pattern may indicate outliers or one-off events.
A rolling average is a simple but effective way to reveal the underlying trend by smoothing out short-term noise and seasonal fluctuations.
Coming Up Next
Next, you'll learn about the Model Based Approach to forecasting Time Series data.