liveBook · Manning

Isnull

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

isnull is a pandas method that returns Boolean values indicating whether each Series or DataFrame value is null or missing.

Think of isnull as a missing-data detector: applied to a Series, it returns True where values are NaN or otherwise null and False elsewhere. Applied to a DataFrame, it preserves the table’s shape while marking each row-column position. Summing the Boolean result counts missing values because True behaves like 1. section 5.0

Use the returned Boolean Series or DataFrame to answer practical cleaning questions:

  • Count missing values in one column with `s.isnull().sum()`. section 5.0
  • Count missing values column by column with `df.isnull().sum()`. section 5.0
  • Inspect the full missing-value pattern with `df.isnull()`. section 5.0
  • Compare missing values with the Series shape to estimate their proportion. section 5.6

Checking ages before conversion

For a celebrity-deaths dataset, test the `age` column before converting it to integers: `df['age'].isnull().sum() / len(df['age'])`. The resulting proportion is 0.004, or 0.4 percent. After assessing that loss, remove missing ages with `df.dropna(subset=['age'])`; later, `pd.to_numeric(..., errors='coerce')` provides another way to turn unparseable values into missing values. section 5.6

Table 5.1 What you need to know (view table figure)

Concept

What is it?

Example

To learn more

df.shape

A two-element tuple indicating the number of rows and columns in a data frame

df.shape

http://mng.bz/8rpg

len(df) or len(df.index)

Gets the number of rows in a data frame

len(df) or len(df.index)

http://mng.bz/EQdr

s.isnull

Returns a boolean series indicating where there are null (typically NaN) values in the series s

s.isnull()

http://mng.bz/N2KX

s.notnull

Returns a boolean series indicating where there are non-null values in the series s

s.notnull()

http://mng.bz/D420

df.isnull

Returns a boolean data frame indicating where there are null (typically NaN) values in the data frame df

df.isnull()

http://mng.bz/lWGz

df.replace

Replaces values in one or more columns with other values

df.replace('a':{'b':'c'), 'd')

http://mng.bz/Bm2q

s.map

Applies a function to each element of a series, returning the result of that application on each element

s.map(lambda x: x**2)

http://mng.bz/d1yz

df.fillna

Replaces NaN with other values

df.fillna(10)

http://mng.bz/rWrE

df.dropna

Removes rows with NaN values

df = df.dropna()

http://mng.bz/V1gr

s.str

Works with textual data

df['colname'].str

http://mng.bz/x4Wq

str.isdigit

Returns a boolean series, indicating which strings contain only the digits 0–9

df['colname'].str.isdigit()

http://mng.bz/AoAE

pd.to_numeric

Returns a series of integers or floats based on a series of strings

pd.to_numeric(df['colname'])

http://mng.bz/Zq2j

df.sort_index

Reorders the rows of a data frame based on the values in its index in ascending order

df = df.sort_index()

http://mng.bz/RxAn

pd.read_excel

Creates a data frame based on an Excel spreadsheet

df = pd.read_excel('myfile.xlsx')

http://mng.bz/2DXN

pd.read_csv

Returns a new data frame based on CSV input

df = pd.read_csv('myfile.csv')

http://mng.bz/wvl7

s.value_counts

Returns a sorted (descending frequency) series counting how many times each value appears in s

s.value_counts()

http://mng.bz/1qzZ

s.unique

Returns a series with the unique (i.e., distinct) values in s, including NaN (if it occurs in s)

s.unique()

http://mng.bz/PzA2

s.mode

Returns a series with the most commonly found values in s

s.mode()

http://mng.bz/7vBm

Use the reference table to compare `s.isnull()` and `df.isnull()` with related shape, non-null, replacement, and mapping operations. section 5.0

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Defines Series and DataFrame results, Boolean summation, and null proportions, but defers broader missing-data strategies.
Examples
Uses Series and DataFrame counts plus a celebrity-deaths age column to measure and remove missing values.
What it assumes
Assumes familiarity with pandas Series, DataFrames, columns, shape, sum, and basic data cleaning.
What you can do after
Apply it via pandas to inspect missingness, count nulls, estimate their proportion, and guide row removal.
How it connects
Connects missing values with sum, shape, dropna, pd.to_numeric, notnull, and DataFrame information reporting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.