I know this adds consecutive columns of same index:
df['C'] = df['A'] + df['B']
But how to add columns of different index:
Lets say I have a dataframe like this:
df
A B
0 9 40
1 1 70
2 5 80
3 8 30
4 7 50
I need to create another column C which is the addition of current index row of column A(i.e. idx) and previous index row of column B(i.e. idx-1), such as:
df
A B C
0 9 40 (9)
1 1 70 (40 + 1)
2 5 80 (70 + 5)
3 8 30 (80 + 8)
4 7 50 (30 + 7)
final result should look like this:
df
A B C
0 9 40 9
1 1 70 41
2 5 80 75
3 8 30 88
4 7 50 37