"People who buy X also buy Y" analysis starts with a crosstab. For two boolean (or categorical) columns, the association-rule measures are:
Implement:
crosstab(df, row, col, normalize=None): pd.crosstab with normalize as None, "index", "columns" or "all"rule_metrics(df, a_col, a_val, b_col, b_val): a dict with support, confidence and lift for the rule "a_col == a_val → b_col == b_val"top_rules(baskets, min_support): baskets is a list of item sets. For every ordered pair of distinct items (A, B) with support ≥ min_support, compute the metrics, and return a list of (A, B, lift) sorted by lift descending, then A, then B.