apache-spark - 比较具有特定误差范围的值
问题描述
有没有办法double
在指定的误差范围内比较 PySpark 中的两个类型值?Essential 类似于这篇文章,但在 PySpark 中。
就像是:
df=#some dataframe with 2 columns RESULT1 and RESULT2
df=withColumn('compare', when(col('RESULT1')==col('RESULT2') +/- 0.05*col('RESULT2'), lit("match")).otherwise(lit("no match"))
但是以更优雅的方式?
解决方案
您可以between
用作条件:
df2 = df.withColumn(
'compare',
when(
col('RESULT1').between(0.95*col('RESULT2'), 1.05*col('RESULT2')),
lit("match")
).otherwise(
lit("no match")
)
)
推荐阅读
- android - 自定义导航抽屉和自定义工具栏
- vue.js - 如何使用 vue.js 检测 div 内的滚动像素
- python-3.x - Python:如何从solve_ivp解释y
- laravel - 从观察者方法加载模型关系
- python - 转换边界框格式
- c++ - 如何将 ASCII 控制字符音译为它们的 UTF-8 符号等价物?
- docker - Docker撰写网络不绑定IP地址
- python - 从验证码图像中删除曲线打开 cv
- ssh - 使用 SSH 的 Bitbucket 管道 yml 部署引发错误
- python - 如何在 Matplotlib 和 Seaborn 中的 x 轴刻度线(不是刻度线标签)和 x 轴之间添加填充