I'm looking to check trends for a number of entities (SysNr)
I have data spanning 3 years (2014,2015,2016)
I'm looking at a large quantity of variables, but will limit this question to one ('res_f_r')
My DataFrame looks something like this
d = [
{'RegnskabsAar': 2014, 'SysNr': 1, 'res_f_r': 350000},
{'RegnskabsAar': 2015, 'SysNr': 1, 'res_f_r': 400000},
{'RegnskabsAar': 2016, 'SysNr': 1, 'res_f_r': 450000},
{'RegnskabsAar': 2014, 'SysNr': 2, 'res_f_r': 350000},
{'RegnskabsAar': 2015, 'SysNr': 2, 'res_f_r': 300000},
{'RegnskabsAar': 2016, 'SysNr': 2, 'res_f_r': 250000},
]
df = pd.DataFrame(d)
RegnskabsAar SysNr res_f_r
0 2014 1 350000
1 2015 1 400000
2 2016 1 450000
3 2014 2 350000
4 2015 2 300000
5 2016 2 250000
My desire is to do a linear regression on each entity (SysNr) and get returned the slope and intercept
My desired output for the above is
SysNr intercept slope
0 1 300000 50000
1 2 400000 -50000
Any ideas?