temporian.EventSet.calendar_hour #
calendar_hour(
tz: Union[str, float, int] = 0
) -> EventSetOrNode
Obtains the hour the timestamps in an
EventSet's sampling are in.
Features in the input are ignored, only the timestamps are used and
they must be unix timestamps (is_unix_timestamp=True).
Output feature contains numbers between 0 and 23.
By default, the timezone is UTC unless the tz argument is specified,
as an offset in hours or a timezone name. See
EventSet.calendar_hour() for an
example using timezones.
Basic example with UTC datetimes
>>> from datetime import datetime
>>> a = tp.event_set(
... timestamps=[datetime(2020,1,1,18,30), datetime(2020,1,1,23,59)],
... )
>>> b = a.calendar_hour()
>>> b
indexes: ...
features: [('calendar_hour', int32)]
events:
(2 events):
timestamps: [...]
'calendar_hour': [18 23]
...
Example with timezone
>>> # UTC datetimes (unless datetime(tzinfo=...) is used)
>>> a = tp.event_set(timestamps=["2020-01-01 09:00",
... "2020-01-01 15:00"])
>>> # Option 1: specify UTC-3 offset in hours
>>> a.calendar_hour(tz=-3)
indexes: ...
'calendar_hour': [ 6 12]
...
>>> # Option 2: specify timezone name (see pytz.all_timezones)
>>> a.calendar_hour(tz="America/Montevideo")
indexes: ...
'calendar_hour': [ 6 12]
...
>>> # No timezone specified, get UTC hour
>>> a.calendar_hour()
indexes: ...
'calendar_hour': [ 9 15]
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tz |
Union[str, float, int]
|
timezone name (see |
0
|
Returns:
| Type | Description |
|---|---|
EventSetOrNode
|
EventSet with a single feature with the hour each timestamp in |