-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpolate based on other column #9616
Comments
Supporting this request, have a similar challenge |
I wrote this function that I think should work to interpolate on a df with any number of value columns, id columns, and a ts column. The id column is optional.
The usage is just
|
Accepted, but it should be |
Big +1 for this feature, it's the only one missing in polars for my daily tasks.
df = pd.DataFrame(
{
"ts": [1, 2.01, 2.00333, 4.2],
"value": [1, None, None, 3],
}
)
df2 = pd.DataFrame(
{
"ts": [0.0, 0.8, 1.0, 2.0, 3.0, 3.5, 4.0]
}
)
df = df.set_index("ts")
df = (
df.reindex(
df.index.union(df2["ts"])
)
.interpolate("index")
.reindex(df2["ts"])
.reset_index()
)
print(df) This is quite cumbersome, hard to remember and hard to read. This does not need to be more complicated than : df = df.interpolate(by=df2["ts"]) What do you think ? |
Agree! I've been wanting to do this for ages but other higher-prio issues keep coming up 😄 Thanks for bringing my attention back to it |
This would be really useful for me too, as would the ability to perform the interpolation within groups according to some column(s), via a |
This looks perfect, thanks Marco! Any idea how close it might be to making it into a release? |
when I get my head out of #16102 😉 I need to resolve some things before 1.0 so I've parked this, hopefully not for too long |
Oh yes! Exactly what I need as well. Can't wait |
Problem description
Based on https://stackoverflow.com/questions/76557773/interpolate-based-on-datetimes
Say we start with
and we want to interpolate the missing values. The missing values are at very irregular intervals, so there's no prospect of using
upsample
From https://stackoverflow.com/a/76564046/4451315 and https://stackoverflow.com/a/76564321/4451315, it's possible to use numpy's
interp
, or scipy'sinterpolate.interp1d
It might be nice to do this without numpy/scipy though, e.g. with one of the following:
df.interpolate(by='ts')
df.interpolate_by('ts')
df.select(pl.col('value').interpolate_by('ts'))
pandas equivalent:
The text was updated successfully, but these errors were encountered: