Skip to content

API: Interpolate at new values #9340

Open
@rubennj

Description

@rubennj

First time I used the .interpolate() method I thought that it receives a new index and then interpolates on it, similar to scipy.interpolate.interp1d
From scipy web:

from scipy import interpolate
x = np.arange(0, 10)
y = np.exp(-x/3.0)
f = interpolate.interp1d(x, y)
xnew = np.arange(0,9, 0.1)
ynew = f(xnew)   # use interpolation function returned by `interp1d`

Later I saw the .reindex() method, so I understood that this role is done by .reindex(). However .reindex() is not really doing a powerful interpolation, just extending the current values using the method keyword.

The current way to achieve it (joining previous and new index and then using .reindex()), in version 0.15.0,

index_joined = df.index.join(new_index, how='outer')
df.reindex(index=index_joined).interpolate().reindex(new_index)

A simpler syntax could be accepting the methods from .interpolate() into the 'method' keyword of .reindex():

df.reindex(index=new_index, method='linear')

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions