hpipy.time_matrix.TimeMatrixMixin#
- class hpipy.time_matrix.TimeMatrixMixin[source]
Bases:
object
Time matrix mixin class.
The class provides a method to create a time matrix from a dataframe consisting of repeat transaction data. The method utilizes datetime data represented as periods and constructs a chronologically ordered matrix.
Methods
Create a time matrix from a dataframe of repeat transactions.
- create_time_matrix(repeat_trans_df)[source]
Create a time matrix from a dataframe of repeat transactions.
This function assumes the dataframe contains columns “period_1” and “period_2” that represent a pair of repeat transactions. The resulting dataframe consists of rows for each transaction pair and columns for each time period, with -1 indicating the first transaction in a pair, 1 indicating the second transaction in a pair, and 0 otherwise.
- Parameters:
repeat_trans_df (pd.DataFrame) – Input DataFrame. Must contain “period_1” and “period_2” columns containing integer values representing periods (i.e., time series expressed as integer).
- Returns:
- DataFrame with columns ‘time_x’, where each row
represents a transaction pair and ‘x’ is a time period between the minimum and maximum periods in the input data.
- Return type:
pd.DataFrame