I have a Spark SQL dataframe consisting of observations for people with a survey date, as follows:
| person_id | survey_date |
|---|---|
| 1 | 2022-03-11 |
| 2 | 2022-02-09 |
| 3 | 2022-01-21 |
| 4 | 2022-04-16 |
person_id is unique, but the dates can be shared or not.
I want to use this table to filter another table with transactions for the people. I only need the transactions that occurred after the survey date (>=)
| person_id | trans_date |
|---|---|
| 1 | 2022-03-10 |
| 1 | 2022-03-14 |
| 1 | 2022-02-11 |
| 2 | 2022-01-30 |
| 2 | 2022-03-07 |
| 2 | 2022-02-16 |
| 3 | 2022-03-02 |
| 4 | 2022-05-15 |
In this case I would only want the following:
| person_id | trans_date |
|---|---|
| 1 | 2022-03-14 |
| 2 | 2022-03-07 |
| 2 | 2022-02-16 |
| 4 | 2022-05-15 |
How to do this?
Data examples:
survey_data = [["1","2022-03-11"],
["2","2022-02-09"],
["3","2022-01-21"],
["4","2022-04-16"]]
transacction_Data =[[ "1", "2022-03-10"],
[ "1", "2022-03-14"],
[ "1", "2022-02-11"],
[ "2", "2022-01-30"],
[ "2", "2022-03-07"],
[ "2", "2022-02-16"],
[ "3", "2022-03-02"],
[ "4", "2022-05-15"]]