Skip to content

Sampling at pre-defined time values #9168

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
amelio-vazquez-reina opened this issue Dec 29, 2014 · 5 comments
Closed

Sampling at pre-defined time values #9168

amelio-vazquez-reina opened this issue Dec 29, 2014 · 5 comments
Labels

Comments

@amelio-vazquez-reina
Copy link
Contributor

amelio-vazquez-reina commented Dec 29, 2014

Consider a time-series, e.g.:

                                 some_quantity
timestamp                 
2014-10-06 18:00:40.063000-04:00      0.568000
2014-10-06 18:00:41.361000-04:00      3.014770
2014-10-06 18:00:42.896000-04:00      0.878154
2014-10-06 18:00:43.040000-04:00      0.723077
2014-10-06 18:00:44.791000-04:00      0.723077
2014-10-06 18:00:45.496000-04:00      0.309539
2014-10-06 18:00:45.799000-04:00      3.032000
2014-10-06 18:00:47.470000-04:00      3.014770
2014-10-06 18:00:48.092000-04:00      1.584616

and an independent set of timestamps, e.g.:

start_time = datetime.datetime(year   = 2014, 
                               month  = 10, 
                               day    = 6, 
                               hour   = 18, 
                               tzinfo = pytz.timezone('US/Eastern')

# Finish 400 seconds later
end_time    = start_time + datetime.timedelta(seconds=400)

new_timestamps = pd.date_range(start = start_time, 
                                  end   = end_time, 
                                  freq  = '2.5s')

Is there any way to sample the original time-series so that, for each of the new timestamps, we get the sum of values of the original time-series between the new time-stamps?

Another way to put it, is there any way to call resample by passing it a series of timestamps on which we want to do the sampling? e.g. something like my_series.resample(how='sum', new_timestamps)

@rockg
Copy link
Contributor

rockg commented Dec 30, 2014

While it is not using passed timestamps, I don't know if that's necessary to get what you are looking for. I think the below does what you want as your passed timestamps would be every 2.5s.

curve.resample('2500L', how='sum')
2014-10-06 18:00:40           3.582770
2014-10-06 18:00:42.500000    2.324308
2014-10-06 18:00:45           6.356309
2014-10-06 18:00:47.500000    1.584616
Freq: 2500L, dtype: float64

Unfortunately, 2.5s is not supported which I think it probably should be. The below is interpreted as 5 rather than 2.5 (I'm pretty sure there is already a request for this).

curve.resample('2.5s', how='sum')
2014-10-06 18:00:40    5.907078
2014-10-06 18:00:45    7.940925

@amelio-vazquez-reina
Copy link
Contributor Author

Thank you @rockg I used new_timestamps with a constant 2.5 second separation as an example. I was hoping there would be a way of passing generic timestamps to pd.resample, but I guess there isn't. is there any way to label this as a feature request? Thanks!

@jreback
Copy link
Contributor

jreback commented Jan 2, 2015

@ribonoous

the soln by @rockg looks right. what exactly is the issue?
(aside from not being able to use 2.5s which is already in #8419 (its a bug/feature)

@jreback jreback added Resample resample method Low-Memory Frequency DateOffsets and removed Low-Memory labels Jan 2, 2015
@amelio-vazquez-reina
Copy link
Contributor Author

Thanks @jreback and @rockg.

@rockg's solution is fine for the example I provided, but I used this example only to convey the problem. In my case, I can't make assumptions about the timestamps (the timestamps may not even come at regular time intervals). They are timestamps arriving asynchronously at the ms scale, and they trigger specific events that we are trying to cross-reference with high precision. Let me know if any of this is still unclear. Thanks.

@mroeschke mroeschke removed the Frequency DateOffsets label Apr 12, 2021
@mroeschke
Copy link
Member

Seems like there hasn't been much interest in this feature over the years so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants