【发布时间】:2016-02-11 02:54:27
【问题描述】:
我有以下数据框:
actual_credit min_required_credit
0 0.3 0.4
1 0.5 0.2
2 0.4 0.4
3 0.2 0.3
我需要添加一列来指示实际信用 >= min_required_credit 的位置。结果是:
actual_credit min_required_credit result
0 0.3 0.4 False
1 0.5 0.2 True
2 0.4 0.4 True
3 0.1 0.3 False
我正在做以下事情:
df['result'] = abs(df['actual_credit']) >= abs(df['min_required_credit'])
但是,第 3 行(0.4 和 0.4)不断导致 False。在各个地方研究了这个问题之后,包括:What is the best way to compare floats for almost-equality in Python?我仍然无法让它工作。每当两列具有相同的值时,结果为 False,这是不正确的。
我正在使用 python 3.3
【问题讨论】:
标签: python pandas floating-point floating-point-comparison inexact-arithmetic