巴西、中国与美国的增长率
现在将分析从各国人均收入的水平扩展到增长率。文件 'income_growth.csv' 包含巴西、中国和美国过去 40 年的人均收入增长率。
您将用 KDE 图将各国历史增长率的分布绘制在同一张图上,以便直观比较这些市场在该时期经历的增长区间。
从本练习起,即使说明未明确要求,您也应在控制台中使用 .info() 检查任何 DataFrame。pandas 已以 pd 导入,seaborn 以 sns 导入,matplotlib.pyplot 以 plt 导入。
本练习是课程的一部分
在 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()