開始使用免費開始

隨時間繪製誤差範圍

在這個練習中,你將使用帶有誤差棒的折線圖,檢視賓夕法尼亞州費城的房價變化。資料來自 ACS 1-year 樣本的 Table B25077。2011 到 2017 年每一年的估計值與誤差範圍都已下載並串接成一個名為 phillypandas DataFrame。ACS 表中的估計值與誤差範圍變數,分別重新命名為 median_home_valuemedian_home_value_moe。(請在主控台查看 DataFrame。)

已將 pandaspd 匿名匯入。

本練習屬於課程

使用 Python 分析美國 Census 資料

檢視課程

練習說明

  • 以別名 plt 匯入 matplotlib.pyplot
  • 建立欄位 rmoe(用來存放房價中位數的相對 MOE),其值為誤差範圍欄位除以估計值欄位後乘以 100
  • 使用 print 輸出 DataFrame,檢視相對 MOE
  • 建立誤差棒圖:第一個引數設為 "year";第二個引數設為房價中位數欄位名稱;參數 yerr 設為房價中位數的 MOE 欄位;最後,data 引數設為 philly DataFrame

動手互動練習

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

# Import graphics packages
import seaborn as sns
sns.set()
____

# Calculate and inspect Relative Margin of Error
philly["rmoe"] = ____
____

# Create line plot with error bars of 90% MOE
plt.errorbar(____, ____, yerr = ____, data = ____)
plt.show()
編輯並執行程式碼