Saturday, 15 May 2010

python - Sampling at pre-defined time values -



python - Sampling at pre-defined time values -

this follow-up question other question: causal resampling: sum on lastly x <time_unit>

say have next time series:

money_spent 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

i sample it:

at pre-defined time points (e.g. range of timestamps every 2.5 seconds starting 18:00 until 19:00) for every sample, sum of spend within interval. update example

for example, assuming generate set of pre-defined timestamps follows:

# start @ 18:00 start_time = datetime.datetime(year = 2014, month = 10, day = 6, hr = 18, tzinfo = pytz.timezone('us/eastern') # finish 400 seconds later end_time = start_time + datetime.timedelta(seconds=400) my_new_timestamps = pd.date_range(start = start_time, end = end_time, freq = '2.5s')

i re-sample original dataframe @ top of post on locations defined my_new_timestamps getting sum of money_spent.

note original dataframe covers ~18:00:40 until ~18:00:48, if do:

resample('2.5s', how='sum', label='right')

the command above only homecoming samples on time-window between these 2 times, , not between start , end times defined my_new_timestamps. sample on 2.5s intervals different ones want (those defined my_new_timestamps).

python datetime numpy pandas timestamp

No comments:

Post a Comment