1

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.

Macaulay
  • 59
  • 1
  • 8
  • We may need to see more about the structure of the dataframe you have, since based on the excerpt you included, I don't see why `df.interpolate()` with the appropriate `axis` parameter wouldn't work. – David Z Jul 27 '17 at 03:38
  • Okay, so using `interpolate(axis=1)` with wide data works for interpolation, although it doesn't like the `id` column being there. It extrapolates using the 'nearest' method, i.e. copying over the 2015 value. – Macaulay Jul 27 '17 at 23:44

0 Answers0