0

I'll explain on example.

I have this data:

id    day   week
1     10    3
2     NaN   4
NaN   NaN   5

And I need this output:

id     [2]
day    [1, 2]
week   False (or smth like this)

Output shows indexes with NaN values ​​for each column.

I have written code for this, but I don't like it:

 index_nan = []
 for col in data.columns:
        if data[col].isnull().sum()==0:
            index_nan.append('False')
        else:
            index_nan.append(str(data[data[col].isna()].index.to_numpy()))
Mary Smith
  • 361
  • 1
  • 2
  • 11
  • Does this answer your question? [How to check if any value is NaN in a Pandas DataFrame](https://stackoverflow.com/questions/29530232/how-to-check-if-any-value-is-nan-in-a-pandas-dataframe) – RichieV Sep 04 '20 at 12:55

1 Answers1

2

use isna

try this,

df=df.isna()
for col in df.columns.values:
    print(col, df.index[df[col]].tolist())

O/P:

id [2]
day [1, 2]
week []
Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111