【发布时间】:2021-08-19 17:23:40
【问题描述】:
假设我有 2 个 spark 数据帧:
Location Date Date_part Sector units
USA 7/1/2021 7/1/2021 Cars 200
IND 7/1/2021 7/1/2021 Scooters 180
COL 7/1/2021 7/1/2021 Trucks 100
Location Date Brands units values
UK null brand1 400 120
AUS null brand2 450 230
CAN null brand3 150 34
我需要我的结果数据框
Location Date Date_part Sector Brands units values
USA 7/1/2021 7/1/2021 Cars 200
IND 7/1/2021 7/1/2021 Scooters 180
COL 7/1/2021 7/1/2021 Trucks 100
UK null 7/1/2021 brand1 400 120
AUS null 7/1/2021 brand2 450 230
CAN null 7/1/2021 brand3 150 34
所以我想要的 df 应该包含来自两个数据框的所有列,我也需要所有行中的 Date_part 这是我尝试过的:
df_result= df1.union(df_2)
但我得到了这个作为我的结果。值正在交换,第二个数据框中的一列丢失。
Location Date Date_part Sector Brands units
USA 7/1/2021 7/1/2021 Cars 200
IND 7/1/2021 7/1/2021 Scooters 180
COL 7/1/2021 7/1/2021 Trucks 100
UK null brand1 400 120
AUS null brand2 450 230
CAN null brand3 150 34
有什么好的建议
【问题讨论】:
标签: python apache-spark pyspark