pynapple.TsdFrame.get_info#
- TsdFrame.get_info(key)[source]#
Returns metadata based on metadata column name or index.
If the metadata name does not contain special nor overlaps with class attributes, it can also be accessed as an attribute.
If the metadata name does not overlap with class-reserved keys, it can also be accessed as a key.
- Parameters:
key –
str: metadata column name or metadata index (for TsdFrame with string column names)
list of str: multiple metadata column names or metadata indices (for TsdFrame with string column names)
Number: metadata index (for TsGroup and IntervalSet)
list, np.ndarray, pd.Series: metadata index (for TsGroup and IntervalSet)
tuple: metadata index and column name (for TsGroup and IntervalSet)
- Returns:
The metadata information based on the key provided.
- Return type:
pandas.Series or pandas.DataFrame or Any (for single location)
- Raises:
IndexError – If the metadata index is not found.
Examples
>>> import pynapple as nap >>> import numpy as np >>> metadata = {"l1": [1, 2, 3], "l2": ["x", "x", "y"]} >>> tsdframe = nap.TsdFrame(t=np.arange(5), d=np.ones((5, 3)), metadata=metadata) >>> print(tsdframe) Time (s) 0 1 2 ---------- -------- -------- -------- 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 3.0 1.0 1.0 1.0 4.0 1.0 1.0 1.0 Metadata -------- -------- -------- -------- l1 1 2 3 l2 x x y dtype: float64, shape: (5, 3)
To access a single metadata column:
>>> tsdframe.get_info("l1") 0 1 1 2 2 3 Name: l1, dtype: int64
To access multiple metadata columns:
>>> tsdframe.get_info(["l1", "l2"]) l1 l2 0 1 x 1 2 x 2 3 y
To access metadata of a single column:
>>> tsdframe.get_info(0) rate 0.667223 l1 1 l2 x Name: 0, dtype: object
To access metadata of multiple columns:
>>> tsdframe.get_info([0, 1]) rate l1 l2 0 0.667223 1 x 1 1.334445 2 x
To access metadata of a single column and metadata key:
>>> tsdframe.get_info((0, "l1")) np.int64(1)
To access metadata as an attribute:
>>> tsdframe.l1 0 1 1 2 2 3 Name: l1, dtype: int64
To access metadata as a key:
>>> tsdframe["l1"] 0 1 1 2 2 3 Name: l1, dtype: int64
Multiple metadata columns can be accessed as keys:
>>> tsdframe[["l1", "l2"]] l1 l2 0 1 x 1 2 x 2 3 y