python - 熊猫有条件地在for循环中删除行
问题描述
我的 Pandas DataFrame 有 17543 行。我想删除一行,前提是每列都包含“nan”。我按照for 循环中的链接删除行尝试了说明, 但没有帮助。以下是我的代码
NullRows=0
for i in range(len(SetMerge.index)):
if(SetMerge.iloc[i].isnull().all()):
df=SetMerge.drop(SetMerge.index[i])
NullRows +=1
print("total null rows : ", NullRows)
我只在 df 中删除了一行,有 17542 行,而 NullRows 输出为 30。
解决方案
drop
不会改变你的SetMerge
. SetMerge
因此,您需要在之后重新分配drop
,或使用其他功能。它是通过您在此处发布并检查的链接写在答案中的。为突变指定 inplace=True 选项。
推荐阅读
- azure - Azure docker 容器给出“未经授权的容器使用”
- javascript - 使用 javascript 从网站获取文本
- python - 在 tf.keras 中使用 softmax 作为顺序层和使用 softmax 作为密集层的激活函数有什么区别?
- gem5 - 我可以在 gem5 中更精细地调试吗?
- python - 在 google colab 中使用 datagen.flow_from_directory 并没有提高训练和验证的准确性
- android - Flutter:为 ImagePicker 使用 Listview.builder
- angular - 如何将 ionic 中的 ccavenue 支付网关与 Angular 集成
- html - 如何隔离标签及其内容
- python - 估计文本文件中值的函数
- jquery - 使用 Asp.net Core MVC Bootstrap 4,对于服务器端添加的模型状态错误,我无法让不显眼的验证正常工作