I have a dataframe similar to the following:
I want to show those columns that any of their rows contain a NaN, NaT or None. If I apply the following code I see what they are:
def null(x):
return any(pd.isnull(x))
print df.apply(null)
It gives me something similar to this:
col1 False
col2 True
col3 False
col4 False
col5 False
col6 True
dtype: bool
I know that those that contain it are those that have a True
.
But now I get a list of hits the columns, some with value True
and others with value False
. How can I make so that only the columns that are True
come out? I have tried the following, but then I only get the result True
but without the name of the column next to it, I feel that I should be close but I can not get it.
def null(x):
if any(pd.isnull(x)) == True:
print any(pd.isnull(x))
print df.apply(null)
This prints me the following,
True
True
EXAMPLE of what I want
col2 True
col6 True
dtype: bool