Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge 2 | Non-Stationary Models
Time Series Analysis

book
Challenge 2

Task

Swipe to start coding

You are faced with a task similar to the previous one: convert data to stationary. You will remove seasonality in the Seasonality Time Series.csv dataset using the difference method. Track a certain amount of time for which the time pattern repeats and use the difference method:

  1. Read the dataset.
  2. Analyze how long patterns repeat (visualize "Var" and "Date" columns of the df DataFrame in this order).
  3. Use the resulting number (it is 8) for the difference method. Perform the differentiation for the "Var" column. Save the obtained result within the df_diff variable.
  4. Visualize the transformed data.

Solution

# Importing libraries
import matplotlib.pyplot as plt
import pandas as pd

# Reading dataset
df = pd.read_csv("https://codefinity-content-media.s3.eu-west-1.amazonaws.com/943e906e-4de6-4694-a1df-313ceed7cfe7/Seasonality+Time+Series.csv")

# Plot dataset before differencing
plt.plot(df["Var"], df["Date"])
plt.show()

# Use differencing method
df_diff = pd.DataFrame(df["Var"]).diff(8)

# Plot dataset after differencing
plt.plot(df_diff)
plt.show()

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 4
single

single

# Importing libraries
import matplotlib.pyplot as plt
import pandas as pd

# Reading dataset
df = pd.read_csv("https://codefinity-content-media.s3.eu-west-1.amazonaws.com/943e906e-4de6-4694-a1df-313ceed7cfe7/Seasonality+Time+Series.csv")

# Plot dataset before differencing
plt.___(df["___"], df["___"])
plt.___()

# Use differencing method
df_diff = pd.DataFrame(df["___"]).___(___)

# Plot dataset after differencing
plt.___(___)
plt.___()

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt