I have two PySpark dataframes which I would like to left join
Prev_table:
| user_id | earnings | start_date | end_date |
|---------|--------|------------|------------|
| 1 | 10 | 2020-06-01 | 2020-06-10 |
| 2 | 20 | 2020-06-01 | 2020-06-10 |
| 3 | 30 | 2020-06-01 | 2020-06-10 |
New_table:
| user_id | profit |
|---------|--------|
| 1 | 100 |
| 2 | 200 |
| 5 | 500 |
The resultant table is a concatanation of the two dataframes grouped by the user_id. And the earnings column is Prev_table.earnings + New_table.profit.
| user_id | earnings | start_date | end_date |
|---------|--------|------------|------------|
| 1 | 110 | 2020-06-01 | 2020-06-10 |
| 2 | 220 | 2020-06-01 | 2020-06-10 |
| 3 | 30 | 2020-06-01 | 2020-06-10 |
| 5 | 500 | | |
This is what Pandas concat would do, but in case of PySpark I believe I need to use PySparks union?
Also I not sure how to do the sum of the two columns.
I know I need to use something like combined_df.agg({"earnings": "sum"}).collect() but having trouble getting this to work.
Would appreciate any guidance on the workflow for this with PySpark. Thank you.