Issue
I basically want to type a formula and apply it on the rest below. My problem is that I don't know how to tell pandas that it has to pick two items out of the same column and for every new calculation, it has to "move down" the cell selection.
Solution
You can do this:
For
a
0 1.0
1 3.0
2 5.0
3 2.0
then
df['d'] =(df['a']+df['a'].shift(-1))*df['a'].shift(-1)
gives
a d
0 1.0 12.0
1 3.0 40.0
2 5.0 14.0
3 2.0 NaN
Answered By - Serge de Gosson de Varennes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.