Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge | Time Series Visualization
Time Series Analysis

book
Challenge

Tâche

Swipe to start coding

You are faced with the task of creating a visualization of the aapl.csv dataset:

  1. Read the dataset. Convert the "Date" column of df to datetime type, and set them as df indexes.
  2. Initialize a line plot for the "Open" column values of the df. Set colormap to "gray".
  3. Add a title to the plot. In this order, it should contain the "Open" column's max and min values.
  4. Add labels on an axis: "Datetime" on the x-axis and "Price" on the y-axis.

Solution

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

# Reading data
df = pd.read_csv("https://codefinity-content-media.s3.eu-west-1.amazonaws.com/943e906e-4de6-4694-a1df-313ceed7cfe7/aapl.csv")
df.index = pd.to_datetime(df["Date"])

# Initializing plot
plt.figure(figsize=(11, 9))
df["Open"].plot(colormap="gray")

# Setting plot title and labels
plt.title("Price | Max: %s | Min: %s" % (max(df["Open"]), min(df["Open"])))
plt.xlabel("Datetime")
plt.ylabel("Price")

# Displaying the plot
plt.show()

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 3
# Importing libraries
import pandas as pd
import matplotlib.pyplot as plt

# Reading data
df = pd.read_csv("https://codefinity-content-media.s3.eu-west-1.amazonaws.com/943e906e-4de6-4694-a1df-313ceed7cfe7/aapl.csv")
df.___ = pd.___(df["Date"])

# Initializing plot
plt.figure(figsize=(11, 9))
df["___"].___(colormap="___")

# Setting plot title and labels
plt.title("Price | Max: %s | Min: %s" % (___(df["Open"]), min(df["___"])))
plt.xlabel("___")
plt.___("___")

# Displaying the plot
plt.show()

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt