-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: IntervalIndex as groups in groupby #37949
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
Comments
I think you can already do this with |
Yes
but it doesn't work with overlapping windows. Unfortunately, |
Note that your example above doesn't use overlapping windows. The IntervalIndex you create with |
Also in general, with the current implementation of |
yes, you are right, the example doesn't cover that, here is one with overlapping intervals: import numpy as np
import pandas as pd
data = pd.DataFrame({'a': [1]*100, 'b': [2]*100}, index=np.arange(0.0, 10, 0.1))
starts = [0.0, 2.5, 5, 7, 3.1] # the last interval overlaps with other intervals
ends = [0.7, 3.8, 6.1, 9.5, 5.2]
means = []
for start, end in zip(starts, ends):
means.append(data.loc[start:end, :].mean()) |
that is good to know - I think I saw it more from a windowing perspective and than noticed that Do you think it might be possible to (ab-)use the |
I am not familiar enough with |
yes the indexers provide a nice approach here cc @mroeschke |
BaseIndexer would be the more appropriate solution if you have arbitrary start and end points, but there are some implicit assumptions:
|
Thank you for your comments!
I was implementing |
Unfortunately no, In theory other APIs could accept it as it just returns start and end bounds but just needs to be implemented. |
Hi there, |
Is your feature request related to a problem?
I often have a list of (variable-size) intervals and I want to aggregate multiple statistics for these intervals.
Describe the solution you'd like
It would be cool (and probably faster) to do:
The text was updated successfully, but these errors were encountered: