I have a data frame df
with columns ID
and N1
, I would like to calculate column N2
, with logic first value should be equal to N1 for each ID and the next value is 0.888/0.999 and so on. And similarly for next ID. Can we do this WITHOUT using for loop in pandas
ID N1 N2
1111 0.999 0.999
1111 0.888 0.888888889
1111 0.777 0.875
1111 0.666 0.857142857
1111 0.555 0.833333333
1111 0.444 0.8
1111 0.333 0.75
2222 0.998 0.998
2222 0.887 0.888777555
2222 0.776 0.874859076
2222 0.665 0.856958763
2222 0.554 0.833082707
2222 0.443 0.799638989
2222 0.332 0.749435666
2222 0.221 0.665662651