Issue
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?
Solution
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()
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.