![](/img/trans.png)
[英]How to a conditional join(like SQL where join) of Dataframes in Python
[英]How to join 2 DataFrames in pyspark sql python
我在 pyspark sql 中有 2 個數據幀
d1
id features result1
1 abc 0
3 def 1
d2
id features result2
1 abc 2
3 def 2
我想像這樣加入數據框
id features result1 result2
1 abc 0 2
3 def 1 2
基本上我想做的就是 append df1 和 result2 列,因為 id 和 features 列具有相同的值。 我嘗試過 union、unionall 和 join,但沒有奏效。
new_df = UnionAll(df1,df2)
new_df = Union(df1,df2)
new_df = df1.join(df2)
任何幫助將不勝感激。
你能試試這個:
joined_df = df1.join(df2, col("df1.features") == col("df2.features"), 'inner')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.