開始使用免費開始

比較 NYC 與 LA 的每週、每月與每年臭氧趨勢

你在影片中已經看過如何對空氣品質的時間序列進行降採樣與彙總。

首先,請把這項新技能用在自 2000 年以來 NYC 與 LA 的臭氧資料上,分別以每週、每月與每年的頻率比較空氣品質趨勢,並觀察不同重採樣期間如何影響視覺化。

本練習屬於課程

Manipulating Time Series Data in Python

檢視課程

練習說明

我們已替你匯入 pandaspd,以及 matplotlib.pyplotplt

  • 使用 pd.read_csv() 匯入 'ozone.csv',並以 'date' 欄位透過 parse_datesindex_col 設定 DateTimeIndex,將結果指派給 ozone,並用 .info() 檢查。
  • ozone 使用 .resample() 設定每週頻率('W'),以 .mean() 彙總並繪圖。
  • 以每月('M')與每年('A')頻率重複上述步驟,並各自繪製結果。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import and inspect data here
ozone = ____


# Calculate and plot the weekly average ozone trend



# Calculate and plot the monthly average ozone trend



# Calculate and plot the annual average ozone trend


編輯並執行程式碼