開始使用免費開始

巴西、中國與美國的成長率

現在把分析從各國人均所得的「水準」擴展到「成長率」。'income_growth.csv' 檔案包含巴西、中國與美國在過去 40 年的人均所得成長率。

你會使用 KDE 圖,將三個國家的歷史成長率分布畫在同一張圖上,方便視覺化比較各市場在這段期間經歷過的成長範圍。

從本課程此處開始,即使說明沒有明確要求,你也應該在主控台用 .info() 檢視任何 DataFrame。pandas 已以 pd 匯入,seabornsns 匯入,matplotlib.pyplotplt 匯入。

本練習屬於課程

在 Python 中匯入與管理財務資料

檢視課程

練習說明

  • 將檔案 'income_growth.csv' 載入到變數 growth。把 'DATE' 欄位解析為 dtype datetime64,並設為索引。
  • 使用合適的函式檢視這三個成長率的摘要統計。
  • 在 for 迴圈中走訪 growth.columns 屬性以取得欄位標籤。大部分程式碼已為你勾勒好。
    • 在每次呼叫 distplot() 時,傳入迴圈變數 column 以選取對應欄位,將參數 hist 設為 False,並將 label 設為 column
    • 顯示結果。

動手互動練習

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

# Load the file into growth
growth = pd.read_csv(____, parse_dates=____).____(____)

# Inspect the summary statistics for the growth rates
growth.____()

# Iterate over the three columns
for column in growth.____:
    sns.____(growth[____], hist=____, label=____)
    
# Show the plot
plt.show()
編輯並執行程式碼