加载多条时间序列
无论是在个人项目中,还是在作为数据科学家进行日常工作时,您很可能会遇到需要同时分析和可视化多条时间序列的情况。
如果每条时间序列的数据分别存放在文件的不同列中,那么使用 pandas 库就可以轻松处理多条时间序列。在接下来的练习中,您将使用一个新的时间序列数据集,其中包含 1944 年至 2012 年美国生产的不同类型肉类的产量。
本练习是课程的一部分
用 Python 可视化时间序列数据
练习说明
我们已使用别名 pd 导入了 pandas。
- 读取位于
url_meat的 CSV 文件,并将其保存为名为meat的 DataFrame。 - 将
meat中的date列转换为datetime类型。 - 将
date列设为meat的索引。 - 打印
meat中所有数值列的汇总统计信息。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Read in meat DataFrame
meat = ____.____(____)
# Review the first five lines of the meat DataFrame
print(meat.head(5))
# Convert the date column to a datestamp type
meat['date'] = ____(____)
# Set the date column as the index of your DataFrame meat
meat = ____.____(____)
# Print the summary statistics of the DataFrame
print(meat.____)