I have a dataframe as shown below. I have to take the rank of the row that has claim_typ as 'PD' and do a difference with the rank of of the current row and add it as a new column.
Source dataframe:
Id svc_dt clm_typ rank
48115882 20180209 RV 1
48115882 20180209 RJ 2
48115882 20180216 RJ 3
48115882 20180302 RJ 4
48115882 20180402 PD 5
48115882 20180502 RJ 6
Expected resultant dataframe:
Id svc_dt clm_typ rank diff_PD_Rank
48115882 20180209 RV 1 4 (Current rank - rank of column with 'PD')
48115882 20180209 RJ 2 3
48115882 20180216 RJ 3 2
48115882 20180302 RJ 4 1
48115882 20180402 PD 5 null
48115882 20180502 RJ 6 null