Challenge
Tâche
Swipe to start coding
You are faced with the task of creating a visualization of the aapl.csv
dataset:
- Read the dataset. Convert the
"Date"
column ofdf
todatetime
type, and set them asdf
indexes. - Initialize a line plot for the
"Open"
column values of thedf
. Setcolormap
to"gray"
. - Add a title to the plot. In this order, it should contain the
"Open"
column's max and min values. - Add labels on an axis:
"Datetime"
on the x-axis and"Price"
on the y-axis.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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 ?
Merci pour vos commentaires !
Section 3. Chapitre 3
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion