简体   繁体   中英

Remove multiple rows based on condition in multiple columns in pandas

I have dataset like this from csv file. 在此处输入图像描述

I want to remove all records that has question mark ('?') in any of their column. I tried this code:

 for column in df.columns: df = df[df[column]?= ' ']

But it does not work, here is the output. 在此处输入图像描述 My expected output is index 1 and 3 get removed. How can i achieve that?

Filter all rows without ? with space:

 out = df[(df?= '.') all(axis=1)]

Or if possible use read_csv and no missing values, only ? use:

 out = pd.read_csv(file, na_values='?').dropna()

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