apache-spark - 比较不等于比较列列表的 Spark 数据帧
问题描述
我目前正在尝试将两个数据帧一起比较,以查看 pyspark 中的字段如何不匹配。我已经能够手动编写它,但我希望能够传递字段列表以确保帧在字段上不匹配。数据帧是相同的。
到目前为止我的代码是:
key_cols = ['team_link_uuid', 'team_sat_hash']
temp_team_sat = orig.select(*key_cols)
temp_team_sat_incremental = delta.select(*key_cols)
hash_field = ['team_sat_hash']
test_update_list = temp_team_sat.join(temp_team_sat_incremental, (temp_team_sat.team_link_uuid == temp_team_sat_incremental.team_link_uuid) & (temp_team_sat.team_sat_hash != temp_team_sat_incremental.team_sat_hash))
但是现在我需要能够获取我的列表(hash_field)并且能够确保一个或多个字段彼此不相等。
解决方案
假设fields_to_compare_list
是您要比较的字段列表,
from functools import reduce
comparaison_query = reduce(
lambda a,b : (a | b),
[ temp_team_sat[col] != temp_team_sat_incremental[col]
for col
in fields_to_compare_list
]
)
test_update_list = temp_team_sat.join(
temp_team_sat_incremental,
on = (temp_team_sat.team_link_uuid == temp_team_sat_incremental.team_link_uuid) \
& comparaison_query
推荐阅读
- reactjs - 导入本地反应 webpack 库的 cdn,在窗口对象中给出一个数字
- go - 如何从另一个文件夹导入主文件夹
- angularjs - 如何在 API Post 请求中使用 [Authorize] 和 [ValidateAntiForgeryToken]?
- php - 将段落拆分为不同的 div
- python - 如何使用 Django 访问静态 css 文件
- android - 在android中动态创建选择芯片
- javascript - 尝试将此 Angular 7 表单提交到我的打字稿上。ngForm 和 [(ngModel)]
- mysql - 我可以自动生成像 pt1234 或 12pt34 或 p12t34 这样的密钥吗
- java - 将清空
在 Liquibase 输入中为我的 spring 实体创建初始 DDL 脚本? - elasticsearch - 弹性搜索缩放浮动不接受数据