I have a Dataframe as follows:
|id |date_1 |date_2 |
+---+----------+-----------+
|0 |2017-01-21|2017-04-01 |
|1 |2017-01-22|2017-04-24 |
|2 |2017-02-23|2017-04-30 |
|3 |2017-02-27|2017-04-30 |
|4 |2017-04-23|2017-05-27 |
|5 |2017-04-29|2017-06-30 |
|6 |2017-06-13|2017-07-05 |
|7 |2017-06-13|2017-07-18 |
|8 |2017-06-16|2017-07-19 |
|9 |2017-07-09|2017-08-02 |
|10 |2017-07-18|2017-08-07 |
|11 |2017-07-28|2017-08-11 |
|12 |2017-07-28|2017-08-13 |
|13 |2017-08-04|2017-08-13 |
|14 |2017-08-13|2017-08-13 |
|15 |2017-08-13|2017-08-13 |
|16 |2017-08-13|2017-08-25 |
|17 |2017-08-13|2017-09-10 |
|18 |2017-08-31|2017-09-21 |
|19 |2017-10-03|2017-09-22 |
+---+----------+-----------+
I know there are many ways to do what I am asking using different pyspark APIs, however I would like to use the Window API to accomplish the following.
It is essentially a double for loop in any other situation.
For every date in date_1, look at every date in date_2 that is in the same or subsequent rows, and count the number of occurrences where the difference falls within a week, month, ..., (the timeframe is irrelevant, but for consistency sake, let's go with week). Use these results to add another column with the count.
The challenge is getting the right Window(s) combination to consider both date columns.