MulaiMulai sekarang secara gratis

Create a time series of air quality data

You have seen in the video how to deal with dates that are not in the correct format, but instead are provided as string types, represented as dtype object in pandas.

We have prepared a data set with air quality data (ozone, pm25, and carbon monoxide for NYC, 2000-2017) for you to practice the use of pd.to_datetime().

Latihan ini adalah bagian dari kursus

Manipulating Time Series Data in Python

Lihat Kursus

Petunjuk latihan

We have already imported pandas as pd and matplotlib.pyplot as plt for you, and loaded the air quality DataFrame into the variable data.

  • Inspect data using .info().
  • Use pd.to_datetime to convert the column 'date' to dtype datetime64.
  • Set the 'date' column as index.
  • Validate the changes by inspecting data using .info() again.
  • Plot data using subplots=True.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

data = pd.read_csv('nyc.csv')

# Inspect data
print(____)

# Convert the date column to datetime64


# Set date column as index


# Inspect data 
print(____)

# Plot data

Edit dan Jalankan Kode