mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-07-14 11:17:47 +08:00
26 lines
655 B
Python
26 lines
655 B
Python
import pandas as pd
|
|
|
|
|
|
def to_pandas(instance: dict, freq: str = None) -> pd.Series:
|
|
"""
|
|
Transform a dictionary into a pandas.Series object, using its
|
|
"start" and "target" fields.
|
|
|
|
Parameters
|
|
----------
|
|
instance
|
|
Dictionary containing the time series data.
|
|
freq
|
|
Frequency to use in the pandas.Series index.
|
|
|
|
Returns
|
|
-------
|
|
pandas.Series
|
|
Pandas time series object.
|
|
"""
|
|
target = instance["target"]
|
|
start = instance["start"]
|
|
if not freq:
|
|
freq = start.freqstr
|
|
index = pd.date_range(start=start, periods=len(target), freq=freq)
|
|
return pd.Series(target, index=index) |