首页 > 解决方案 > KeyError:'[] not found in axis' 在具有相同长度的数据帧中

问题描述

我有 n 个包含时间序列数据的数据框。其中一个比其他的粒度更高,所以我在 Pandas 中使用 drop() 修复了它。举例来说,考虑三个数据帧 data1、data2、data3,其中 data3 具有更高的粒度。所以,我要做的是:

while exceeding data is found:
   data3.drop([i], inplace=True)

在这个过程之后,我检查了所有数据帧的长度,它们的大小相等,这意味着前面的过程是成功的。如果我理解正确,pandas 在执行时会为我重新分配索引inplace=True

但是当我尝试排除一些这样的重复数据时(在上一个过程之后):

while duplicate data:
   data1.drop([j], inplace=True)
   data2.drop([j], inplace=True)
   data3.drop([j], inplace=True)

执行 drop in data3 时出现以下错误:

'{} not found in axis'.format(labels[mask]))
KeyError: '[37621] not found in axis'

我确定数据长度高于37621

更新:数据框是大小为 44700 的一维数据。

标签: pandas

解决方案


推荐阅读