Filter missing records
Data cleaning
Pandas · Function
Detect whether a scalar or array-like object contains non-missing values. The result is a scalar Boolean for scalar input and a corresponding Boolean structure for array-like input.
pd.notna accepts either one value or an array-like object and checks each value for missingness. It returns one Boolean for scalar input, or a Boolean-shaped result matching the input container for array-like input.
pandas.notna(obj)| Name | Type | Description |
|---|---|---|
obj | array-like or object value | Object to check for not null or non-missing values. |
bool or array-like of bool. Scalar input returns a scalar Boolean; array-like input returns corresponding Boolean indicators.
import numpy as np
import pandas as pd
values = pd.Series([1, np.nan, None, "ok"])
mask = pd.notna(values)
print(mask.tolist()) # [True, False, False, True]Creates a boolean mask that identifies which Series entries contain non-missing values.
Data cleaning
Validation
Exploration
pd.notna returns True for a valid value and False for a missing one. With a scalar it returns a scalar bool; with array-like input it returns a corresponding Boolean result.
Follow-up: How would you retain only valid rows in a DataFrame column? Apply the returned mask, for example, df[pd.notna(df["column"])].
The function recognizes missing values according to pandas' missing-data rules, including NaN for numeric data, None or NaN in object data, and NaT for datetimelike data.
Follow-up: Would an empty string be removed by this test? No: the documentation says empty strings are not considered NA.
For a Series or DataFrame, the result contains Boolean values aligned with the input's shape and labels. Each output position indicates whether the corresponding input value is valid.
Follow-up: How can you count valid entries in a Series? Use pd.notna(series).sum(), because True values contribute one.
pandas.isnapandas.isnullpandas.notnullSeries.notnaDataFrame.notna