etna.datasets.apply_alignment#

apply_alignment(df: DataFrame, alignment: Dict[str, Timestamp] | Dict[str, int], original_timestamp_name: str | None = None)[source]#

Apply given alignment to a dataframe.

Applying alignment creates a new dataframe in which we have a new ‘timestamp’ column with sequential integer timestamps.

For each segment we sort timestamps and assign them sequential integer values (with step 1) in a way that timestamp in alignment gets value 0.

Parameters:
  • df (DataFrame) – Dataframe in a long format.

  • alignment (Dict[str, Timestamp] | Dict[str, int]) – Alignment to apply.

  • original_timestamp_name (str | None) – Name for a column to save the original timestamps. If None original timestamps won’t be saved.

Returns:

Aligned dataframe in a long format.

Raises:
  • ValueError: – Parameter df isn’t in a long format.

  • ValueError: – There is a segment in df which isn’t present in alignment.

  • ValueError: – There is a segment which doesn’t have a timestamp that is present in alignment.