2

I have some data taken every minute and I want to resample it in 5 minute segments.

df.resample("5T").mean()

This has the effect of resampling to every fifth minute of the hour. i.e 12:00,12:05,12:10,12:15 etc.

What if my last data point was 12:07

Is there a way to resample it in 5 minute blocks to the result would be (also backwards so the last newest time 100% contains data from 5 minutes)

12:07, 12:02, 11:07 etc

Lewis Morris
  • 1,916
  • 2
  • 28
  • 39

1 Answers1

2

Use origin parameter by first value of index:

rng = pd.date_range('2017-04-03 12:07:00', periods=10, freq='min')
df = pd.DataFrame({'a': range(10)}, index=rng)  

df = df.resample("5T", origin=df.index[0]).mean()
print (df)
                     a
2017-04-03 12:07:00  2
2017-04-03 12:12:00  7
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252