确定相似的金额
Identify similar amounts
我正在尝试开发一个读取一系列金额的凭证,然后确定哪个金额与我拥有的大致金额相对应。
例如,我想找到一种方法使脚本与以下金额大致匹配:150.38
100.00
150.50 #this would be the match
200.38
240.00
300.25
我怎样才能让脚本理解这些数量是“相等的”?
如你的情况,求浮点数的绝对相对距离,找到最小距离的第一次出现,显示:
dist = (df['numbers'] - closest_to).abs()
dist.idxmin()
closest = df.iloc[dist.idxmin()]
完整示例:
#creating dataframe
data = {'numbers':[100.00,150.50,200.38,240.00,300.25]}
df = pd.DataFrame(data).astype(float)
#setting closest value
closest_to = 150.38
#find closest
dist = (df['numbers'] - closest_to).abs()
dist.idxmin()
closest = df.iloc[dist.idxmin()]
closest
输出:
numbers 150.5
Name: 1, dtype: float64
我正在尝试开发一个读取一系列金额的凭证,然后确定哪个金额与我拥有的大致金额相对应。
例如,我想找到一种方法使脚本与以下金额大致匹配:150.38
100.00
150.50 #this would be the match
200.38
240.00
300.25
我怎样才能让脚本理解这些数量是“相等的”?
如你的情况,求浮点数的绝对相对距离,找到最小距离的第一次出现,显示:
dist = (df['numbers'] - closest_to).abs()
dist.idxmin()
closest = df.iloc[dist.idxmin()]
完整示例:
#creating dataframe
data = {'numbers':[100.00,150.50,200.38,240.00,300.25]}
df = pd.DataFrame(data).astype(float)
#setting closest value
closest_to = 150.38
#find closest
dist = (df['numbers'] - closest_to).abs()
dist.idxmin()
closest = df.iloc[dist.idxmin()]
closest
输出:
numbers 150.5
Name: 1, dtype: float64