创建 DateTimeIndex
拥有 DatetimeIndex 有多种好处。首先,您可以用方括号语法选取任意时间段,或只用一行代码就能画出折线图。
请在已加载的 apple 股票数据集上练习这些操作,其中 Date 已是一个 datetime 列。
本练习是课程的一部分
Python 中的异常检测
练习说明
- 将
Date列设置为appleDataFrame 的索引。 - 绘制一条红色折线图,展示苹果股票
Open列从 2008 年 7 月初到 2013 年 12 月 9 日的走势。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Set the Date column as a DatetimeIndex
apple.____(____)
# Plot the opening prices for the instructed range
apple____
plt.title("Opening prices of Apple stocks from the beginning of July of 2008 to December of 2013.")
plt.show()