Home > Mobile >  Python Pandas Series Keep Only Null Columns
Python Pandas Series Keep Only Null Columns

Time:08-10

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?

CodePudding user response:

It is isna and isnull

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