pyspark - 从 pyspark 数据框中删除具有相同值但在不同列中的重复行
问题描述
我想从两列中删除重复的行。包含两个值的行具有相同的记录,但顺序相反。
|--------------|-------------------|
| name | alt_name |
|----------------------------------|
| a10.samsung | a20.samsung |
| x.iphone | xr.iphone |
| 3.nokia | 5.nokia |
| a20.samsung | a10.samsung |
| 5.nokia | 3.nokia |
| xr.iphone | x.iphone |
------------------------------------
我想要以下输出;
|--------------|-------------------|
| name | alt_name |
|----------------------------------|
| 3.nokia | 5.nokia |
| a10.samsung | a20.samsung |
| x.iphone | xr.iphone |
------------------------------------
解决方案
你可以使用 spark sql 来做到这一点:
我假设您的原始数据框名称为 mobiles 和删除重复项的代码:
mobiles.createTempView('tablename')
newDF= spark.sql("select * from tablename where name<=alt_name")
newDF.show()
推荐阅读
- shell - 用于在模式中查找字符串的 Shell 脚本
- c# - 读取具有唯一标识符 ID 的表
- shell - jq json解析数组元素
- python-3.6 - Impala 查询不以异步方式执行
- android - E/AndroidRuntime:致命异常:主 PID:4435
- bash - AWK - 如何使用命令行参数进行过滤 ($1)
- numpy - 如何解释 numpy 数组中的 PIL 图像
- javascript - 使用图像数据向服务器发送 ajax 请求(laravel5.1)
- macos - 我的 App 上似乎启用了沙盒,但 App Store 不同意
- python - 图像不在开始菜单中。游戏