How To Find Non Missing Values In A DataFrame?
Table Of Contents:
- Syntax ‘notna( )’ Method In Pandas.
- Examples ‘notna( )’ Method.
(1) Syntax:
DataFrame.notna()
Description:
- Detect existing (non-missing) values.
- Return a boolean same-sized object indicating if the values are not NA.
- Non-missing values get mapped to True. Characters such as empty strings
''
ornumpy.inf
are not considered NA values (unless you setpandas.options.mode.use_inf_as_na = True
). - NA values, such as None or
numpy.NaN
, get mapped to False values.
Returns:
- DataFrame –
- Mask of bool values for each element in DataFrame that indicates whether an element is not an NA value.
(2) Examples Of notna() 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 Not NA.
df.notna()
Output:
# Count Of Missing Values In Each Column
df.notna().sum()
Output:
age 2
born 2
name 3
toy 2
dtype: int64
# Percentage Of Missing Values In Each Column
(df.notna().sum()/len(df))*100
Output:
age 66.666667
born 66.666667
name 100.000000
toy 66.666667
dtype: float64