How To Find Missing Values In A DataFrame?
Table Of Contents:
- Syntax ‘isna( )’ Method In Pandas.
- Examples ‘isna( )’ Method.
(1) Syntax:
DataFrame.isna()
Description:
Detect missing values.
Return a boolean same-sized object indicating if the values are NA. NA values, such as None or
numpy.NaN
, gets mapped to True values.Everything else gets mapped to False values. Characters such as empty strings
''
ornumpy.inf
are not considered NA values (unless you setpandas.options.mode.use_inf_as_na = True
).
Returns:
- DataFrame
- Mask of bool values for each element in DataFrame that indicates whether an element is an NA value.
(2) Examples Of isna() Method:
Example-1:
df = pd.DataFrame(dict(age=[5, 6, np.NaN],
born=[pd.NaT, pd.Timestamp('1939-05-27'),
pd.Timestamp('1940-04-25')],
name=['Alfred', 'Batman', ''],
toy=[None, 'Batmobile', 'Joker']))
df
Output:
# Show which entries in a DataFrame are NA.
df.isna()
Output:
# Count Of Missing Values In Each Column
df.isna().sum()
Output:
age 1
born 1
name 0
toy 1
dtype: int64
# Percentage Of Missing Values In Each Column
(df.isna().sum()/len(df))*100
Output:
age 33.333333
born 33.333333
name 0.000000
toy 33.333333
dtype: float64