I have a data frame like below and it's structure is not fixed, it can have different number of column at different moment.
A_Name B_Info Value_Yn Value_Yn-1 Value_Yn-2 ...... Value_Y1
0 AA X1 0.9 0.8 0.7 ...... 0.1
1 BB Y1 0.1 0.2 0.3 ...... 0.9
2 CC Z1 -0.9 -0.8 -0.7 ...... -0.1
3 DD L1 -0.1 -0.2 -0.3 ...... -0.9
I want to perform a linear regression for each row where values of X and Y are as
X = [n, n-1, n-2, .....2, 1]
Y = [Value_Yn, Value_Yn-1, Value_Yn-2.......Value_Y2, Value_Y1]
Here 'n' is number of column that will be prefixed with 'Value_'
Let's assume that n = 9
I will have value of
For Row 0
X = [9, 8, 7, 6, 5, 4, 3, 2, 1]
Y = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1]
For Row 1
X = [9, 8, 7, 6, 5, 4, 3, 2, 1]
Y = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
Similarly for other rows...
I want output in this format...
A_Name B_Info Intercept Slope_Coefficent
0 AA X1 0 0.1
1 BB Y1 1 -0.1
2 CC Z1 0 -0.1
3 DD L1 -1 0.1
Data-set is large and doing it by looping is not the correct way...
