0

While looking for an answer of how to check NaN values, I found this stack overflow post.

How to check if any value is NaN in a Pandas DataFrame

I used the answer by hobs. But I am getting exactly same results with or without the last transpose method.

nan_rows = df[df.isnull().T.any().T]

nan_rows = df[df.isnull().T.any()]

Exactly the same rows return for both the statements. Is there any specific reason that the answer mentioned has additional T ?

Edward
  • 4,443
  • 16
  • 46
  • 81
shantanuo
  • 31,689
  • 78
  • 245
  • 403

1 Answers1

1

I do not think we need adding a T at the end , since df.isnull().T.any() give out a pd.Series

df.isnull().T.any()
Out[33]: 
0    False
1     True
2     True
dtype: bool
df.isnull().T.any().T
Out[34]: 
0    False
1     True
2     True
dtype: bool

Also why not

df.isnull().any(axis = 1)
Out[37]: 
0    False
1     True
2     True
dtype: bool
BENY
  • 317,841
  • 20
  • 164
  • 234