简体   繁体   中英

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,

图片

I just need to remove all rows that shows 'nan%' both in 'Precision' and in 'Recall'. dropna() does not work here.

You can select all rows if not equal nan% in both columns:

df[df[['Precison','Recall']].ne('nan%').all(axis=1)]

Or you can replace all nan% to NaN for working DataFrame.dropna :

df = df.replace('nan%', np.nan).dropna(subset=['Precison','Recall'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM