gpt4 book ai didi

python - 使用 df.iterrows() 时删除 Pandas 数据框中的一行

转载 作者:行者123 更新时间:2023-12-05 06:18:23 27 4
gpt4 key购买 nike

如果当前行某列数据缺失,我需要删除该行。

这是我写的:

for c, r in data.iterrows():
if (r['A'] == ""):
data = data.drop(r)

但我收到错误:

"unreadable key error"

最佳答案

试试这个,使用 boolean indexing :

data[data['A'] != ""]

data['A'] != "" 作为 bool 系列返回,对于值不是 ""的每一行都为 True。

关于python - 使用 df.iterrows() 时删除 Pandas 数据框中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61278504/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com