我有两个 pyspark 数据框如下:
df1 = spark.createDataFrame(
["yes","no","yes23", "no3", "35yes", """41no["maybe"]"""],
"string"
).toDF("location")
df2 = spark.createDataFrame(
["yes","no"],
"string"
).toDF("location")
我想检查位置col 中的值是否来自df1、startsWith、df2位置col 中的值,反之亦然。
就像是 :
df1.select("location").startsWith(df2.location)
以下是我在这里期待的输出:
+-------------+
| location|
+-------------+
| yes|
| no|
| yes23|
| no3|
+-------------+
使用 spark SQL 对我来说看起来最简单:
df1.createOrReplaceTempView('df1')
df2.createOrReplaceTempView('df2')
joined = spark.sql("""
select df1.*
from df1
join df2
on df1.location rlike '^' || df2.location
""")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句