中国、インド、米国のインフレ動向
最後に、seaborn パッケージには、カテゴリ変数の水準の分布を可視化するための関数が用意されています。
次の2つの演習では、FRED のデータを使って、過去50年以上にわたる中国、インド、米国のインフレ率の推移を確認します。さきほど学んだ関数を使う前に、生データに慣れておきましょう。pandas は pd、matplotlib.pyplot は plt、seaborn は sns としてインポート済みです。FRED のインフレデータは inflation としてワークスペースに用意されています。
この演習はコースの一部です
Pythonでの金融データのインポートと管理
演習の手順
.info()を使ってinflationを確認します。inflationを'Country'でグループ化し、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()