Reputation: 2478
I am using the Auto MPG dataset which contains missing values in the column/attribute horsepower
in the form of ?
characters.
Hence when I use the code-
data.isnull.values.any()
OR
data["horsepower"].isnull.values.any()
Both of them return False
since these codes work for NaN values or blank values.
How can I locate such missing values containing special character, which in my case happens to be ?
rather than the traditional NaN value(s).
Thanks!
Upvotes: 2
Views: 1248
Reputation: 134
you need to convert ?
to NaN
first.
After then You can go for finding null values in it.
1) to convert ?
to NaN
:
data.replace('?',np.NaN)
2) to find null values:
pd.isna(data['horsepower'])
it will return dataframe with series of True/False
.
Upvotes: 1
Reputation: 75080
you can define na_values
as ?
or use the below:
df.replace(r'[\W]',np.nan,regex=True)
\W
finds any character that is not a letter, numeric digit, or the underscore character.
Upvotes: 2