开始使用免费开始使用

中国、印度和美国的通胀趋势

最后,seaborn 包提供了一些函数,可以可视化分类变量不同水平的分布。

接下来的两个练习中,您将查看来自 FRED 的过去 50 多年里中国、印度和美国的历史通胀数据。在直接使用刚学到的函数之前,先熟悉一下原始数据更有帮助。pandas 已以 pd 导入,matplotlib.pyplot 已以 plt 导入,seaborn 已以 sns 导入。FRED 的通胀数据已作为 inflation 提供在您的工作区中。

本练习是课程的一部分

在 Python 中导入与管理金融数据

查看课程

练习说明

  • 使用 .info() 查看 inflation
  • 'Country'inflation 分组,并将结果赋给 inflation_by_country
  • 在一个 for 循环中,遍历 inflation_by_country 返回的 countrydata 配对。在每次迭代中,对 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()
编辑并运行代码