Parmandeep Chaddha
Parmandeep Chaddha

Reputation: 514

Python Pandas Series Keep Only Null Columns

I have a pandas Series that has None values in some columns. I would like to keep only the keys with None values. There must be a native pandas function that does this! For DataFrames, it's easy to create a mask and filter, but not sure how to do it for a Series.

Example Input:

import pandas as pd

my_series = pd.Series({
    "foo": "some string",
    "bar": "some string",
    "bam": None,
})

Expected Output

new_series =my_series.DO_SOMETHING()
new_series = pd.Series({
    "bam": None,
})

What would this DO_SOMETHING be?

Upvotes: 0

Views: 71

Answers (1)

BENY
BENY

Reputation: 323356

It is isna and isnull

my_series[my_series.isnull()] # isna
Out[824]: 
bam    None
dtype: object

Upvotes: 1

Related Questions