Python | Pandas dataframe.notna ()

NumPy | Python Methods and Functions

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.

# import pandas as pd

import pandas as pd

 
# Create first data frame

df = pd.DataFrame ({ "A" : [ 14 , 4 , 5 , 4 , 1 ],

"B" : [ 5 , 2 , 54 , 3 , 2 ], 

"C" : [ 20 , 20 , 7 , 3 , 8 ],  

"D" : [ 14 , 3 , 6 , 2 , 6 ]})

  
# Print the data frame
df

Let`s use the dataframe.notna () function to find all non-missing values ​​in the data frame.

# find non-values ​​
df.notna ()

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.

# import pandas as pd

import pandas as pd

 
# Create data frame

df = pd.DataFrame ({ "A" : [ 12 , 4 , 5 , None , 1 ],

" B " : [ 7 , 2 , 54 , 3 , None ] , 

"C" : [ 20 , 16 , 11 , 3 , 8 ],

  "D" : [ 14 , < / code> 3 , None , 2 , 6 ]})

  
# find not missing values ​​
df.notna ()

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.





Get Solution for free from DataCamp guru