Skip to content

ENH: Add 'end' option in resample's origin #37804

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

Closed
GYHHAHA opened this issue Nov 13, 2020 · 0 comments · Fixed by #38408
Closed

ENH: Add 'end' option in resample's origin #37804

GYHHAHA opened this issue Nov 13, 2020 · 0 comments · Fixed by #38408
Labels
Milestone

Comments

@GYHHAHA
Copy link
Contributor

GYHHAHA commented Nov 13, 2020

In some cases I need to calculate the time group from the end of time series instead of the beginning.

For example, if user uses s.resample('7min', origin='end', closed='right') , the following expected groups are (09:23:45, 09:30:45], (09:16:45, 09:23:45], (09:09:45, 09:16:45], ... , (08:20:45, 08:27:45]. And under normal cases, closed should be right when origin is end since last value should serve as the end value of the last group.

>>>idx = pd.date_range('20200101 8:26:35', '20200101 9:31:58', freq='77s')
>>>idx
DatetimeIndex(['2020-01-01 08:26:35', '2020-01-01 08:27:52',
               '2020-01-01 08:29:09', '2020-01-01 08:30:26',
               '2020-01-01 08:31:43', '2020-01-01 08:33:00',
               ... ...
               '2020-01-01 09:25:37', '2020-01-01 09:26:54',
               '2020-01-01 09:28:11', '2020-01-01 09:29:28',
               '2020-01-01 09:30:45'],
              dtype='datetime64[ns]', freq='77S')
>>>data = np.ones(len(idx))
>>>s = pd.Series(data,index=idx)
>>>s
2020-01-01 08:26:35    1.0
2020-01-01 08:27:52    1.0
2020-01-01 08:29:09    1.0
.... ...
2020-01-01 09:23:03    1.0
2020-01-01 09:24:20    1.0
2020-01-01 09:25:37    1.0
2020-01-01 09:26:54    1.0
2020-01-01 09:28:11    1.0
2020-01-01 09:29:28    1.0
2020-01-01 09:30:45    1.0
Freq: 77S, dtype: float64

Thus the sum operation on this resampler shows:

>>>s.resample('7min', origin='end', closed='right').sum()
2020-01-01 08:27:45    1.0
2020-01-01 08:34:45    6.0
2020-01-01 08:41:45    5.0
2020-01-01 08:48:45    6.0
2020-01-01 08:55:45    5.0
2020-01-01 09:02:45    6.0
2020-01-01 09:09:45    5.0
2020-01-01 09:16:45    6.0
2020-01-01 09:23:45    5.0
2020-01-01 09:30:45    6.0
Freq: 7T, dtype: float64
@GYHHAHA GYHHAHA added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 13, 2020
@jreback jreback added this to the 1.2 milestone Nov 26, 2020
@jreback jreback added Resample resample method and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 26, 2020
@jreback jreback modified the milestones: 1.2, Contributions Welcome Nov 28, 2020
@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants