I have a table as below:
Rate Distance
Start 4
Coupon 7
Coupon 8
End 10
Start 13
Coupon 14
End 18
And I want to calculate the another column as Density that will take the value at df["Rate"] == "End" and subtract with the value at df["Rate"] == "Start" and then divide the count of coupons between Start and End with the subtracted value as output below:
Rate Distance Density
Start 4 0.33
Coupon 7 0.33
Coupon 8 0.33
End 10 0.33
Start 13 5
Coupon 14 5
End 18 5