The Pandas dataframe.notna()
function detects existing / non-missing values in a dataframe. The function returns a boolean that has the same size as the object to which it is applied, indicating whether each individual value is a na
value or not. All non-missing values are displayed as true, and missing values are displayed as false.
Note: Characters such as empty strings "or numpy.inf are not considered NA values. (unless you set pandas.options.mode.use_inf_as_na = True).
Syntax: DataFrame.notna ()
Returns: Mask of bool values for each element in DataFrame that indicates whether an element is not an NA value
Example # 1: Use notna ()
to find all non-missing values in the data frame.
|
Let’s use the dataframe.notna ()
function to find all non-missing values in the data frame.
|
Output:
As we can see in the output, all non-missing values in the data frame have been matched against true. There is no false value because there is no missing value in the data frame.
Example # 2: Use notna ()
to find non-missing values when in notna ()
there are missing values.
|
Output:
As we can see in the output, cells that have na
values have been mapped as false and all cells that have non-missing values have been mapped as true.