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:
- Read the dataset.
- Analyze how long patterns repeat (visualize
"Var"
and"Date"
columns of thedf
DataFrame in this order). - Use the resulting number (it is
8
) for the difference method. Perform the differentiation for the"Var"
column. Save the obtained result within thedf_diff
variable. - Visualize the transformed data.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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?
Thanks for your feedback!
Section 5. Chapter 4
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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
Ask AI
Ask anything or try one of the suggested questions to begin our chat