Python Pandas Series Keep Only Null Columns

Question:

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?

Asked By: Parmandeep Chaddha

||

Answers:

It is isna and isnull

my_series[my_series.isnull()] # isna
Out[824]: 
bam    None
dtype: object
Answered By: BENY
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.