I have a table, such in below
ID Index_month Month_ID
1 201701 201701
1 201701 201702
1 201701 201703
1 201701 201704
1 201701 201705
1 201701 201706
2 201501 201701
2 201501 201702
2 201501 201703
2 201501 201704
2 201501 201705
2 201501 201706
and I want to calculate the length from their Index month to the max month_ID, for example, for ID 1, the length should be 201706 - 201701 which 6 months; and for ID 2, the length 201706 - 201501 which is 30 months
the desire output is
ID length
1 6
2 30
both Index_month and Month_ID are integer, at the beginning, I just use Month_ID - Index_month, but 201706 - 201501 will get 305.
Is there any month_between function in Pyspark that can do the trick?