I have panel data in a dataframe:
id pop2010 pop2015
1001 1000 1300
1002 500 650
...
I want to linearly interpolate the data for each year between 2010 and 2015, and then create a new column for pop2016
and linearly extrapolate for this year. How can I do this?
I can reshape to 'long' data (using pd.wide_to_long()
), and then use df.interpolate()
to do the interpolation. But if I create a column for pop2016
and then reshape and interpolate, it interpolates using values from different municipalities (indexed by id
), which I don't want. So I need to interpolate first, and then reshape back to wide format, but I'm not sure how to proceed.
Other answers don't seem very helpful, since they don't address panel data.