[英]delete 'nan' rows and not "NaN" in pandas
I need to delete the rows that contains 'nan%' in in the 'Precison' and 'Recall' columns, as below image shows,我需要删除“精确”和“召回”列中包含“nan%”的行,如下图所示,
I just need to remove all rows that shows 'nan%' both in 'Precision' and in 'Recall'.我只需要删除在“精度”和“召回”中都显示“nan%”的所有行。 dropna() does not work here.
dropna() 在这里不起作用。
You can select all rows if not equal nan%
in both columns:如果两列中的
nan%
不相等,您可以选择所有行:
df[df[['Precison','Recall']].ne('nan%').all(axis=1)]
Or you can replace all nan%
to NaN
for working DataFrame.dropna
:或者您可以将所有
nan%
替换为NaN
以用于工作DataFrame.dropna
:
df = df.replace('nan%', np.nan).dropna(subset=['Precison','Recall'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.