I would like to do below in python using dataframe and custom apply function.
Month,1,2,3,4,5
Oct 2018,0.1,0.2,0.3,0.4,NaN
Nov 2018,0.5,1.0,1.5,NaN,NaN
First row is column headers. I would like to take each row and do a linear fit and populate slope and intercept into a separate column. For example, "Oct 2018" row has x:[1,2,3,4],y:[0.1,0.2,0.3,0.4] should give slope=0.1 and intercept=0.0 whereas "Nov 2018" row has x:[1,2,3], y:[0.5,1.0,1.5] should give slope=0.5 and intercept=0.0.
I am getting x values from column names. Thanks in advance.