pandas - 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 的一维数据。
解决方案
推荐阅读
- javascript - 我的代码在 $(document).ready() 函数中不起作用。谁能帮我理解为什么?
- cassandra - apache cassandra 3.11.2 nodetool 清理错误 java.lang.AssertionError: null
- java - 如何在 Java 运行时使用 Spring 执行本机 SQL 查询?
- reactjs - 测试函数返回不同的案例场景 - Jest 酶
- docker - Jenkinsfile 没有使用完整的 docker-compose 命令,丢失 build-arg
- python - 带有requests.exceptions.ConnectionError退避的Python解决方法将不起作用
- c# - 在一个特征文件中添加多个标签
- angular - Angular如何将ngModel数据从一个组件传递到另一个组件?
- c# - 如何为所有控制器方法返回通用/通用响应对象?
- google-cloud-platform - Cloud Dataprep - 用中间数据集的值替换代码或 ID