Search code examples
pandasdataframemissing-data

How can I view the indexes or another associated value of missing values from a dataframe?


If I know that there were missing values in my email_address column, how can I iterate through it and return the indexes or names of the associated missing values?

I used this code but I don't know what's wrong

surveydf
surveydf.isnull()
for i in surveydf['email_address']:
    if surveydf.isnull() is True:
        print(surveydf['first_name'])
    else:
        pass

Solution

  • identify the rows with nan values:

    surveydf['email_address'].isna()
    

    use that as a mask:

    surveydf[surveydf['email_address'].isna()]['first_name']
    

    create a list out of the 'first_name' column where isna() is True:

    list(surveydf[surveydf['email_address'].isna()]['first_name'])