0
votes

I am trying to interpolate a DataFrame with some uneven years like orig_years = [2020, 2022, 2030, 2038, 2040] to something like given_years = [2020, 2025, 2030, 2035, 2040, 2045, 2050].

Here is a dummy DataFrame that I am working on:

df:
Out[344]: 
      FUEL  YEAR  VALUE
0      gas  2022   1000
1      gas  2030    500
2      oil  2020      5
3      oil  2040     10
4  biomass  2030    100
5  biomass  2038    100

The years are uneven how can I interpolate them? I would appreciate any ideas.

Expected output: As you see, this is a result of interpolate(limit_direction = 'both')

REGION FUEL YEAR VALUE 0 DE gas 2020 1000.00 1 DE oil 2020 5.00 2 FR biomass 2020 100.00 4 DE gas 2025 750.00 5 DE oil 2025 6.25 6 FR biomass 2025 100.00 .. ... ... ... ... 10 FR biomass 2035 100.00 11 DE oil 2035 8.75 12 DE gas 2035 500.00 14 DE gas 2040 500.00 15 FR biomass 2040 100.00 16 DE oil 2040 10.00

Thank you.

1
what is your expected output ?BENY
@YOBEN_S I added.Dariyoush

1 Answers

1
votes

You can use np.arange

>>> df.YEAR = np.arange(2020, 2020 + (5*len(df)), 5)
>>> df
      FUEL  YEAR  VALUE
0      gas  2020   1000
1      gas  2025    500
2      oil  2030      5
3      oil  2035     10
4  biomass  2040    100
5  biomass  2045    100