中国、印度和美国的通胀趋势
最后,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()