Change language

Python | Pandas dataframe.notnull ()

The Pandas dataframe.notnull() 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.notnull ()

Returns: Mask of bool values ​​for each element in DataFrame that indicates whether an element is not an NA value.

Example # 1: Use notnull () 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" : [ "Sam" , "olivia" , " terica " , " megan " , "amanda" ],

"C" : [ 20 + 5j , 20 + 3j , 7 , 3 , 8 ],

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

 
# Print the data frame
df

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

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

Output:

As we can see in the output, everything is not missing values ​​in the data frame have been matched against true. There is no false value since there is no missing value in the data frame

Example # 2: Use notnull () to find non-missing values ​​when in notnull () there are missing values.

# import pandas as pd

import pandas as pd

 
# Create data frame

df = pd.DataFrame ({ "A" : [ " Sandy " , " alex " , "brook" , "kelly" , np.nan], 

"B" : [np.nan, "olivia" , "terica" ​​ , " ", " amanda"],

"C" : [ 20 + 5j , 20 + 3j , 7 , None , 8 ],

  "D" : [ 14.8 , 3 , None , 2.3 , 6 ]})

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

Output:

Note that an empty string is also displayed as true, indicating that it is not a NaN value.

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically