Pandas DataFrame notna() method with examples

Spread the love

The notna method in pandas detect existing (non-missing) values in a dataframe or series. It return a boolean same-sized object indicating if the values are not NA. Non-missing values get mapped to True.

Syntax –

DataFrame.notna()

Examples –

Let’s read a dataset to work with.

import pandas as pd

url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/fruit_prices.csv'
df = pd.read_csv(url)
df.head()

1 . Show which entries in a DataFrame are not NA –

To show which entries in a DataFrame are not NA, we can use the notna method in pandas.

df.notna()

2 . Show which entries in a Series are not NA –

We can also use notna method with a series.

# create a series
s = df['apple']

# check which entries in the series are not NA
s.notna()

Rating: 1 out of 5.

Leave a Reply