Search code examples
pythonpandasdataframeinterpolation

linear interpolation between two data points


I have two data points x and y:

  x = 5 (value corresponding to 95%)
  y = 17 (value corresponding to 102.5%)

No I would like to calculate the value for xi which should correspond to 100%.

 x = 5 (value corresponding to 95%)
 xi = ?? (value corresponding to 100%)
 y = 17 (value corresponding to 102.5%)

How should I do this using python?


Solution

  • is that what you want?

    In [145]: s = pd.Series([5, np.nan, 17], index=[95, 100, 102.5])
    
    In [146]: s
    Out[146]:
    95.0      5.0
    100.0     NaN
    102.5    17.0
    dtype: float64
    
    In [147]: s.interpolate(method='index')
    Out[147]:
    95.0      5.0
    100.0    13.0
    102.5    17.0
    dtype: float64