Find empty or NaN entry in Pandas Dataframe

前端 未结 8 2451
不思量自难忘°
不思量自难忘° 2020-12-05 04:17

I am trying to search through a Pandas Dataframe to find where it has a missing entry or a NaN entry.

Here is a dataframe that I am working with:

cl_         


        
相关标签:
8条回答
  • 2020-12-05 04:46

    Partial solution: for a single string column tmp = df['A1'].fillna(''); isEmpty = tmp=='' gives boolean Series of True where there are empty strings or NaN values.

    0 讨论(0)
  • 2020-12-05 04:46

    Another opltion covering cases where there might be severar spaces is by using the isspace() python function.

    df[df.col_name.apply(lambda x:x.isspace() == False)] # will only return cases without empty spaces
    

    adding NaN values:

    df[(df.col_name.apply(lambda x:x.isspace() == False) & (~df.col_name.isna())] 
    
    0 讨论(0)
  • 2020-12-05 04:48

    I've resorted to

    df[ (df[column_name].notnull()) & (df[column_name]!=u'') ].index

    lately. That gets both null and empty-string cells in one go.

    0 讨论(0)
  • 2020-12-05 04:54

    Try this:

    df[df['column_name'] == ''].index
    

    and for NaNs you can try:

    pd.isna(df['column_name'])
    
    0 讨论(0)
  • 2020-12-05 05:00

    you also do something good:

    text_empty = df['column name'].str.len() > -1

    df.loc[text_empty].index

    The results will be the rows which are empty & it's index number.

    0 讨论(0)
  • 2020-12-05 05:05

    To obtain all the rows that contains an empty cell in in a particular column.

    DF_new_row=DF_raw.loc[DF_raw['columnname']=='']
    

    This will give the subset of DF_raw, which satisfy the checking condition.

    0 讨论(0)
提交回复
热议问题