temporian.EventSet.set_index #
set_index(indexes: Union[str, List[str]]) -> EventSetOrNode
Replaces the index in an EventSet
.
Usage example
>>> a = tp.event_set(
... timestamps=[1, 2, 1, 0, 1, 1],
... features={
... "f1": [1, 1, 1, 2, 2, 2],
... "f2": [1, 1, 2, 1, 1, 2],
... "f3": [1, 1, 1, 1, 1, 1]
... },
... indexes=["f1"],
... )
>>> # "f1" is the current index
>>> a
indexes: [('f1', int64)]
features: [('f2', int64), ('f3', int64)]
events:
f1=1 (3 events):
timestamps: [1. 1. 2.]
'f2': [1 2 1]
'f3': [1 1 1]
f1=2 (3 events):
timestamps: [0. 1. 1.]
'f2': [1 1 2]
'f3': [1 1 1]
...
>>> # Set "f2" as the only index, remove "f1"
>>> b = a.set_index("f2")
>>> b
indexes: [('f2', int64)]
features: [('f3', int64), ('f1', int64)]
events:
f2=1 (4 events):
timestamps: [0. 1. 1. 2.]
'f3': [1 1 1 1]
'f1': [2 1 2 1]
f2=2 (2 events):
timestamps: [1. 1.]
'f3': [1 1]
'f1': [1 2]
...
>>> # Set both "f1" and "f2" as indices
>>> b = a.set_index(["f1", "f2"])
>>> b
indexes: [('f1', int64), ('f2', int64)]
features: [('f3', int64)]
events:
f1=1 f2=1 (2 events):
timestamps: [1. 2.]
'f3': [1 1]
f1=1 f2=2 (1 events):
timestamps: [1.]
'f3': [1]
f1=2 f2=1 (2 events):
timestamps: [0. 1.]
'f3': [1 1]
f1=2 f2=2 (1 events):
timestamps: [1.]
'f3': [1]
...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indexes |
Union[str, List[str]]
|
List of index / feature names (strings) used as the new indexes. These names should be either indexes or features in the input. |
required |
Returns:
Type | Description |
---|---|
EventSetOrNode
|
EventSet with the updated indexes. |
Raises:
Type | Description |
---|---|
KeyError
|
If any of the specified |