0
我有兩個Dataframes A和B,如:如何計算兩個數據框中兩列的布爾值?
A Dataframes is:
+----+-----+
| k| v|
+----+-----+
|key1|False|
|key2|False|
|key3|False|
|key4|False|
|key5|False|
|key6|False|
+----+-----+
B Dataframes is:
+----+----+
| k| v|
+----+----+
|key2|True|
|key3|True|
+----+----+
我想加入A和B表k個列,並計算V色譜柱,結果一樣:
+----+-----+
| k| v|
+----+-----+
|key1|False|
|key2|True |
|key3|True |
|key4|False|
|key5|False|
|key6|False|
+----+-----+
我推測代碼如下:
A.join(B,'k','left_out')
但是,我不知道如何計算v列
。我借@Vitaliy Kotlyarenko的想法修改我的代碼:
from pyspark.sql import functions as F
A.join(B,'k','left_out').withColumn('value', F.col('v') & F.col('v')).drop('v')