1. Learn
  2. /
  3. 课程
  4. /
  5. Python 中的时间序列数据处理

Connected

道练习

比较多类资产的表现

您在视频中已经看到,可以把多条时间序列的起点归一化到 100 来轻松比较它们,并绘制结果。

为了更全面地看待金融市场,我们来比较四类关键资产:股票、债券、黄金和原油。

说明

100 XP

我们已经将 pandas 导入为 pd,将 matplotlib.pyplot 导入为 plt。

  • 使用 .read_csv() 导入 'asset_classes.csv',解析 'DATE' 列为日期并将其设为索引,将结果赋给 prices。
  • 在 prices 上使用 .iloc[0] 选择每个序列的第一个价格,将结果赋给 first_prices。
  • 用 prices 除以 first_prices,再乘以 100,将结果赋给 normalized。
  • 绘制 normalized。