Reading and Visualizing Data
The first thing to start with is reading the data. When working with time series, the rules of the game do not change - you can still use pandas to get data from csv files.
In the files, let's say you have a Date column that contains dates in str type. For further time series analysis, you must turn the str type into a datetime. This is implemented using the pandas function to_datetime()
Let's take the dataset air_quality_no2_long.csv as an example:
dataset = pd.read_csv("daily-total-female-births.csv")
Next, we convert the data type in the Date column from str to datetime:
dataset["Date"] = pd.to_datetime(dataset["Date"])
You can also do this immediately when reading the dataset:
dataset = pd.read_csv("daily-total-female-births.csv", parse_dates=["Date"])
Now we can plot our dataset:
fig, ax = plt.subplots(figsize=(11, 9))
ax.plot(dataset["Date"], dataset["Births"])
ax.set_xlabel("Datetime")
ax.set_ylabel("Births")
plt.show()
Swipe to start coding
Read and visualize the AirPassengers.csv dataset.
- Import
matplotlib.pyplotasplt. - Read the
csvfile and save it within thedatavariable. - Convert
"Month"intodatetimetype. - Initialize a line plot with the
"Month"column ofdataon the x-axis and"#Passengers"on the y-axis. - Set labels on an axis and display the plot:
"Month"on the x-axis;"Passengers"on the y-axis.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Zusammenfassen Sie dieses Kapitel
Code in file erklären
Erklären, warum file die Aufgabe nicht löst
Awesome!
Completion rate improved to 3.85
Reading and Visualizing Data
Swipe um das Menü anzuzeigen
The first thing to start with is reading the data. When working with time series, the rules of the game do not change - you can still use pandas to get data from csv files.
In the files, let's say you have a Date column that contains dates in str type. For further time series analysis, you must turn the str type into a datetime. This is implemented using the pandas function to_datetime()
Let's take the dataset air_quality_no2_long.csv as an example:
dataset = pd.read_csv("daily-total-female-births.csv")
Next, we convert the data type in the Date column from str to datetime:
dataset["Date"] = pd.to_datetime(dataset["Date"])
You can also do this immediately when reading the dataset:
dataset = pd.read_csv("daily-total-female-births.csv", parse_dates=["Date"])
Now we can plot our dataset:
fig, ax = plt.subplots(figsize=(11, 9))
ax.plot(dataset["Date"], dataset["Births"])
ax.set_xlabel("Datetime")
ax.set_ylabel("Births")
plt.show()
Swipe to start coding
Read and visualize the AirPassengers.csv dataset.
- Import
matplotlib.pyplotasplt. - Read the
csvfile and save it within thedatavariable. - Convert
"Month"intodatetimetype. - Initialize a line plot with the
"Month"column ofdataon the x-axis and"#Passengers"on the y-axis. - Set labels on an axis and display the plot:
"Month"on the x-axis;"Passengers"on the y-axis.
Lösung
Danke für Ihr Feedback!
single