我有两个具有不同类型列的数据框。我需要加入这两个不同的数据框。请参考下面的例子
val df1 has
Customer_name
Customer_phone
Customer_age
val df2 has
Order_name
Order_ID
Run Code Online (Sandbox Code Playgroud)
这两个数据框没有任何公共列。两个数据框中的行数和列数也不同。我试图插入一个新的虚拟列来增加 row_index 值,如下所示 val dfr=df1.withColumn("row_index",monotonically_increasing_id())。
但是当我使用 Spark 2 时,不支持 monotonically_increasing_id 方法。有什么方法可以连接两个数据框,以便我可以在一张 Excel 文件中创建两个数据框的值。
例如
val df1:
Customer_name Customer_phone Customer_age
karti 9685684551 24
raja 8595456552 22
val df2:
Order_name Order_ID
watch 1
cattoy 2
Run Code Online (Sandbox Code Playgroud)
我的最终 excel 表应该是这样的:
Customer_name Customer_phone Customer_age Order_name Order_ID
karti 9685684551 24 watch 1
raja 8595456552 22 cattoy 2
Run Code Online (Sandbox Code Playgroud)