# DifferencingTransform¶

class DifferencingTransform(in_column: str, period: int = 1, order: int = 1, inplace: bool = True, out_column: Optional[str] = None)[source]

Calculate a time series differences.

This transform can work with NaNs at the beginning of the segment, but fails when meets NaN inside the segment.

Notes

To understand how transform works we recommend: Stationarity and Differencing

Create instance of DifferencingTransform.

Parameters
• in_column (str) – name of processed column

• period (int) – number of steps back to calculate the difference with, it should be >= 1

• order (int) – number of differences to make, it should be >= 1

• inplace (bool) –

• if True, apply transformation inplace to in_column,

• if False, add transformed column to dataset

• out_column (Optional[str]) –

• if set, name of added column, the final name will be ‘{out_column}’;

• if isn’t set, name will be based on `self.__repr__()`

Raises
• ValueError: – if period is not integer >= 1

• ValueError: – if order is not integer >= 1

Inherited-members

Methods

 `fit`(df) Fit the transform. `fit_transform`(df) May be reimplemented. Apply inverse transformation to DataFrame. Make a differencing transformation.
fit(df: pandas.core.frame.DataFrame) [source]

Fit the transform.

Parameters

df (pandas.core.frame.DataFrame) – dataframe with data.

Returns

result

Return type

DifferencingTransform

inverse_transform(df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

Apply inverse transformation to DataFrame.

Parameters

df (pandas.core.frame.DataFrame) – DataFrame to apply inverse transform.

Returns

result – transformed DataFrame.

Return type

pd.DataFrame

transform(df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

Make a differencing transformation.

Parameters

df (pandas.core.frame.DataFrame) – dataframe with data to transform.

Returns

result – transformed dataframe

Return type

pd.Dataframe