開始使用免費開始

2010 年以來紐約市的移動平均空氣品質

上一支影片介紹了移動視窗函式。為了練習這個新工具,你將從 2010 年以來的紐約市空氣品質趨勢開始。你會使用美國環保署提供的每日臭氧(Ozone)濃度資料,計算並繪製 90 天與 360 天的移動平均。

本練習屬於課程

Manipulating Time Series Data in Python

檢視課程

練習說明

我們已經將 pandaspd 匯入,並將 matplotlib.pyplotplt 匯入。

  • 使用 pd.read_csv() 匯入 'ozone.csv',從 'date' 欄位建立 DateTimeIndex(使用 parse_datesindex_col),並將結果指定為 data
  • 新增欄位 '90D''360D',其內容為欄位 'Ozone' 的 90 與 360 曆日的 .mean() 移動平均。
  • 繪製自 2010 年起的 data,並將標題(title)設為 'New York City'

動手互動練習

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

# Import and inspect ozone data here
data = ____
print(____)

# Calculate 90d and 360d rolling mean for the last price
data['90D'] = ____
data['360D'] = ____

# Plot data

編輯並執行程式碼