中國、印度與美國的通膨走勢
最後,seaborn 套件提供了用來視覺化類別變數各層級分布的函式。
在接下來的兩個練習中,你會使用來自 FRED 的資料,檢視過去 50 多年中國、印度與美國的歷史通膨資料。在開始使用你剛學到的函式之前,先熟悉原始資料會更好。pandas 以 pd、matplotlib.pyplot 以 plt、seaborn 以 sns 已經為你匯入。FRED 的通膨資料已放在你的工作空間中,名稱為 inflation。
本練習屬於課程
在 Python 中匯入與管理財務資料
練習說明
- 使用
.info()檢視inflation。 - 以
'Country'對inflation分組,並指定給inflation_by_country。 - 在 for 迴圈中,逐一取出
inflation_by_country回傳的country、data組合。每次迭代時,對data呼叫.plot(),並將title設為country,以顯示歷史時間序列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Inspect the inflation data
inflation.____()
# Create inflation_by_country
inflation_by_country = inflation.____(____)
# Iterate over inflation_by_country and plot the inflation time series per country
for country, data in inflation_by_country:
# Plot the data
data.____(____=____)
# Show the plot
plt.show()