hpipy.time_matrix.TimeMatrixMixin.create_time_matrix#

TimeMatrixMixin.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