I've got a list of over 500k people. The data looks like the first table. I'd like to use the admission date from the first table and if the admission date of the same person in the second table is within 30 days of their admission date in the first table then I'd like to store that overlapping record in the third table. The example of what I'd like is below. Is there a faster way to do this than using iterrows using the person_ids and dates from the first table and checking every row in the second table?
Table 1
| person_id | admission_date | value |
| 1234 | 2017-01-31 | 6 |
| 5678 | 2018-03-20 | 12 |
| 9101 | 2017-02-22 | 11 |
| 1234 | 2020-10-31 | 19 |
| 5678 | 2019-06-16 | 21 |
| 9101 | 2021-12-14 | 8 |
Table 2
| person_id | admission_date | value |
| 1234 | 2015-01-31 | 10 |
| 1234 | 2017-02-12 | 152 |
| 5678 | 2017-01-31 | 10 |
| 5678 | 2018-04-10 | 10 |
| 9101 | 2017-02-25 | 99 |
| 9101 | 2017-03-01 | 10 |
| 1234 | 2012-12-31 | 10 |
| 5678 | 2019-07-10 | 11 |
| 9101 | 2017-01-31 | 10 |
Table 3
| person_id | admission_date | value |
| 1234 | 2017-02-12 | 152 |
| 5678 | 2018-04-10 | 10 |
| 9101 | 2017-02-25 | 99 |
| 9101 | 2017-03-01 | 10 |
| 5678 | 2019-07-10 | 11 |