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?
CodePudding user response:
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()