Skip to content

temporian.from_pandas #

from_pandas(
    df: pandas.DataFrame,
    indexes: Optional[List[str]] = None,
    timestamps: str = "timestamp",
    name: Optional[str] = None,
    same_sampling_as: Optional[EventSet] = None,
) -> EventSet

Converts a Pandas DataFrame into an EventSet.

The column timestamps (defaults to "timestamp") contains the timestamps. Columns indexes (default to None, equivalent to []), contains the indexes. The remaining columns are converted into features.

See tp.event_set() for the list of supported timestamp and feature types.

Usage example
>>> df = pd.DataFrame(
...     data=[
...         [1.0, 5, "A"],
...         [2.0, 6, "A"],
...         [3.0, 7, "B"],
...     ],
...     columns=["timestamp", "feature_1", "feature_2"],
... )
>>> evset = tp.from_pandas(df, indexes=["feature_2"])

Parameters:

Name Type Description Default
df DataFrame

A non indexed Pandas dataframe.

required
indexes Optional[List[str]]

Names of the columns to use as indexes. If empty (default), the data is not indexed. Only integer and string columns can be used as indexes.

None
timestamps str

Name of the column containing the timestamps. See tp.event_set() for the list of supported timestamp types.

'timestamp'
name Optional[str]

Optional name of the EventSet. Used for debugging, and graph serialization.

None
same_sampling_as Optional[EventSet]

If set, the new EventSet is checked and tagged as having the same sampling as same_sampling_as. Some operators, such as EventSet.filter(), require their inputs to have the same sampling.

None

Returns:

Type Description
EventSet

An EventSet.

Raises:

Type Description
ValueError

If indexes or timestamps are not in df's columns.

ValueError

If a column has an unsupported dtype.