i have a dataframe something like this
JavaScript
x
11
11
1
d1 d2 d3 d4
2
780 37.0 21.4 122840.0
3
784 38.1 21.4 122860.0
4
846 38.1 21.4 122880.0
5
843 38.0 21.5 122900.0
6
820 36.3 22.9 133220.0
7
819 36.3 22.9 133240.0
8
819 36.4 22.9 133260.0
9
820 36.3 22.9 133280.0
10
822 36.4 22.9 133300.0
11
how do i get the sum of values between the same column in a new column in a dataframe for example:
JavaScript
1
5
1
d1 d2 d3 d4 d5
2
780 37.0 21.4 122840.0 1564
3
784 38.1 21.4 122860.0 1630
4
846 38.1 21.4 122880.0 1689
5
i want a new column with the sum of d1[i] + d1[i+1] .i know .sum() in pandas but i cant do sum between the same column
Advertisement
Answer
Your question is not fully clear to me, but I think what you mean to do is:
JavaScript
1
2
1
df['d5'] = df['d1'] + df['d1'].shift(-1)
2
Now you have to decide what you want to happen for the last element of the series.