How to drop rows of Pandas DataFrame whose value in a certain column is NaN

前端 未结 12 998
一生所求
一生所求 2020-11-22 00:59

I have this DataFrame and want only the records whose EPS column is not NaN:

>>> df
                 STK_ID           


        
12条回答
  •  一个人的身影
    2020-11-22 01:35

    You could use dataframe method notnull or inverse of isnull, or numpy.isnan:

    In [332]: df[df.EPS.notnull()]
    Out[332]:
       STK_ID  RPT_Date  STK_ID.1  EPS  cash
    2  600016  20111231    600016  4.3   NaN
    4  601939  20111231    601939  2.5   NaN
    
    
    In [334]: df[~df.EPS.isnull()]
    Out[334]:
       STK_ID  RPT_Date  STK_ID.1  EPS  cash
    2  600016  20111231    600016  4.3   NaN
    4  601939  20111231    601939  2.5   NaN
    
    
    In [347]: df[~np.isnan(df.EPS)]
    Out[347]:
       STK_ID  RPT_Date  STK_ID.1  EPS  cash
    2  600016  20111231    600016  4.3   NaN
    4  601939  20111231    601939  2.5   NaN
    

提交回复
热议问题