How to find the indices of rows in a pandas DataFrame containing NaN values in Python

Finding the indices of rows in a pandas.DataFrame containing NaN values results in a list of the indices of the rows in the DataFrame which contain at least one NaN.

Solution for How to find the indices of rows in a pandas DataFrame containing NaN values in Python : You can use pandas.isnull() to find the indices of rows in a DataFrame containing NaN Use the syntax for index, row in pandas.DataFrame.iterrows() to iterate over each index, row pair in pandas.DataFrame. At each iteration, call row.isnull() to return a boolean pandas.Series indicating whether each element in row is NaN. Use pandas.Series.any() to check whether any element in the previous result pandas.Series is True. If so, use list.append(index) to append index to an initially empty list.

Use a list comprehension for a more concise implementation.

rows_with_nan = [index for index, row in df.iterrows() if row.isnull().any()]


how-to-find-the-indices-of-rows-in-a-pandas-dataframe-containing-nan-values-in-python