I am new in pyspark and I need help to search in df.
I have df1 with students data as follows
+---------+----------+--------------------+
|studentid| course | registration_date |
+---------+----------+--------------------+
| 348| 2| 15-11-2021 |
| 567| 1| 05-11-2021 |
| 595| 3| 15-10-2021 |
| 580| 2| 06-11-2021 |
| 448| 4| 15-09-2021 |
+---------+----------+--------------------+
df2. Have info about the registration periods as follows
+--------+------------+------------+
| period | start_date | end_date |
+--------+------------+------------+
| 1| 01-09-2021 | 15-09-2021 |
| 2| 16-09-2021 | 30-09-2021 |
| 3| 01-10-2021 | 15-10-2021 |
| 4| 16-10-2021 | 31-10-2021 |
| 5| 01-11-2021 | 15-11-2021 |
| 6| 16-11-2021 | 30-11-2021 |
+--------+------------+------------+
I need to iter df1 row by row, get student registration_date and with this date, go to df2 and get the period information with condition df2.start_date <= df1.registration_date <= df2.end_date.
Result will be new df as follows
+---------+----------+--------------------+--------+------------+------------+
|studentid| course | registration_date | period | start_date | end_date |
+---------+----------+--------------------+--------+------------+------------+
| 348| 2| 15-11-2021 | 5| 01-11-2021 | 15-11-2021 |
| 567| 1| 05-11-2021 | 5| 01-11-2021 | 15-11-2021 |
| 595| 3| 15-10-2021 | 3| 01-10-2021 | 15-10-2021 |
| 580| 2| 06-11-2021 | 5| 01-11-2021 | 15-11-2021 |
| 448| 4| 15-09-2021 | 1| 01-09-2021 | 15-09-2021 |
+---------+----------+--------------------+--------+------------+------------+