I want to find the value of a new column dev for each row of a dataframe such that:
n=100
slope=0.8
inv=3
for i in range(0,n):
dev += math.pow(src[i] - (slope * (n - i) + inv), 2)
Where src is a list of the previous n values of a column of the same dataframe.
Thus if my dataframe is:
Index A
0 1
1 2
2 4
3 5
4 2
And if the value of n is 3, the src for the row with index 3 will be:
[4, 2, 1]
What would be the most efficient way of going about this?