Comparing floats in a pandas column

前端 未结 3 1871
一生所求
一生所求 2020-12-09 02:44

I have the following dataframe:

       actual_credit    min_required_credit
   0   0.3              0.4
   1   0.5              0.2
   2   0.4              0         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 03:19

    Due to imprecise float comparison you can or your comparison with np.isclose, isclose takes a relative and absolute tolerance param so the following should work:

    df['result'] = df['actual_credit'].ge(df['min_required_credit']) | np.isclose(df['actual_credit'], df['min_required_credit'])
    

提交回复
热议问题