Round the Timestamp to the specified resolution.
Frequency string indicating the rounding resolution.
The behavior is as follows:
bool contains flags to determine if time is dst or not (note that this flag is only applicable for ambiguous fall dst dates).
âNaTâ will return NaT for an ambiguous time.
âraiseâ will raise an AmbiguousTimeError for an ambiguous time.
A nonexistent time does not exist in a particular timezone where clocks moved forward due to DST.
âshift_forwardâ will shift the nonexistent time forward to the closest existing time.
âshift_backwardâ will shift the nonexistent time backward to the closest existing time.
âNaTâ will return NaT where there are nonexistent times.
timedelta objects will shift nonexistent times by the timedelta.
âraiseâ will raise an NonExistentTimeError if there are nonexistent times.
Notes
If the Timestamp has a timezone, rounding will take place relative to the local (âwallâ) time and re-localized to the same timezone. When rounding near daylight savings time, use nonexistent
and ambiguous
to control the re-localization behavior.
Examples
Create a timestamp object:
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
A timestamp can be rounded using multiple frequency units:
>>> ts.round(freq='h') # hour Timestamp('2020-03-14 16:00:00')
>>> ts.round(freq='min') # minute Timestamp('2020-03-14 15:33:00')
>>> ts.round(freq='s') # seconds Timestamp('2020-03-14 15:32:52')
>>> ts.round(freq='ms') # milliseconds Timestamp('2020-03-14 15:32:52.193000')
freq
can also be a multiple of a single unit, like â5minâ (i.e. 5 minutes):
>>> ts.round(freq='5min') Timestamp('2020-03-14 15:35:00')
or a combination of multiple units, like â1h30minâ (i.e. 1 hour and 30 minutes):
>>> ts.round(freq='1h30min') Timestamp('2020-03-14 15:00:00')
Analogous for pd.NaT
:
When rounding near a daylight savings time transition, use ambiguous
or nonexistent
to control how the timestamp should be re-localized.
>>> ts_tz = pd.Timestamp("2021-10-31 01:30:00").tz_localize("Europe/Amsterdam")
>>> ts_tz.round("h", ambiguous=False) Timestamp('2021-10-31 02:00:00+0100', tz='Europe/Amsterdam')
>>> ts_tz.round("h", ambiguous=True) Timestamp('2021-10-31 02:00:00+0200', tz='Europe/Amsterdam')
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4