I would like to round (floor) a Pandas Timestamp
using a pandas.tseries.offsets
(like when resampling time series but with just one row)
import pandas as pd
from pandas.tseries.frequencies import to_offset
freq = to_offset("H")
dt = pd.Timestamp('2017-01-03 05:02:00')
# what should I do
# to get pd.Timestamp('2017-01-03 05:00:00')
I wonder if pandas.core.resample.TimeGrouper
can't help
grouper = pd.Grouper(freq="H")
Timestamps may be rounded down using a time frequency string:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Timestamp.floor.html
There may be a way to do it with offsets, but if you're just trying to "floor" timestamps to the format
'%H:00:00'
, you could also just use thereplace
method thatpd.Timestamps
inherit fromdatetime.datetime
(see this answer)If you wanted to do this on a whole column of datetimes, you could just apply it as a lambda: