I want to round a DateTime feature such a way that it gets converted to the start value of every 10 minute time interval. Example below shows the desired result:
     Actual Time              |        Round Time(within 10 min interval)
  2016-01-01 05:47:46                      2016-01-01 05:40:00
  2016-01-01 05:49:58                      2016-01-01 05:40:00
  2016-01-01 05:50:01                      2016-01-01 05:50:00
  2016-01-01 05:59:58                      2016-01-01 05:50:00  
Code below, rounds it to nearest 10 minute interval instead of always giving the floor value.
df['DateTime'].agg(lambda x : x.round('10min'))
It rounds the DateTime Feature to the nearest value.
   Actual Time              |        Round Time(within 10 min interval)
  2016-01-01 05:47:46                      2016-01-01 05:50:00
  2016-01-01 05:49:58                      2016-01-01 05:50:00
  2016-01-01 05:50:01                      2016-01-01 05:50:00
  2016-01-01 05:59:58                      2016-01-01 06:00:00  
Round time such a way that it falls near the floor value.
Use Series.dt.floor:
df['Round Time'] = df['DateTime'].dt.floor('10min')
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With