更多数据清洗:缺失数据
当您打印 DataFrame intraday 的长度时,会发现有几行缺失。若某个 1 分钟区间内没有成交,就会出现缺失数据。要查看哪些行缺失,可以取两个集合的差:完整的每分钟集合,减去包含缺失行的 DataFrame 索引对应的集合。填补缺失行后,您可以将索引转换为一天中的时间,然后绘制数据。
股票以离散的 1 美分价位成交(尽管有一小部分成交价会落在 1 美分价位之间),而不是连续价格。绘图时,您会注意到股价会在 1 美分的区间内来回跳动较长一段时间。这通常被称为 "bid/ask bounce"(买卖盘跳动)。
本练习是课程的一部分
Python 中的时间序列分析
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Notice that some rows are missing
print("If there were no missing rows, there would be 391 rows of minute data")
print("The actual length of the DataFrame is:", len(___))