How to expand distance between values in pandas dataframe?
A
1 3
2 5
3 6
5 5
6 9
I want to increase the distance between adjacent elements by x times, for example by two times.
Expected output:
A B
1 3 3
2 5 7 # (3 + 2 * 2)
3 6 9 # (7 + 1 * 2)
5 5 7 # (9 - 1 * 2)
6 9 15 # (7 + 4 * 2)
>Solution :
Solution from comment – multiple A by 2 and subtract first value:
df['B'] = df['A'].mul(2) - df['A'].iat[0]
print (df)
A B
1 3 3
2 5 7
3 6 9
5 5 7
6 9 15