text_plain_output_1.png
from apyori import apriori

import pandas as pd

df = pd.read_csv('../input/grocery-products-purchase-data/Grocery Products Purchase.csv')

df1 = df.melt(var_name='columns', value_name='index')

unique_values = pd.DataFrame(df1['index'].value_counts())

transacts = []
for i in range(len(df)):
    transacts.append([str(df.values[i, j]) for j in range(len(df.columns))])

from apyori import apriori
rules = apriori(transactions=transacts, min_support=0.001, min_confidence=0.05, min_lift=1.01, min_length=2, max_length=2)

output = list(rules)
def inspect(output):
    lhs = [tuple(result[2][0][0])[0] for result in output]
    rhs = [tuple(result[2][0][1])[0] for result in output]
    support = [result[1] for result in output]
    confidence = [result[2][0][2] for result in output]
    lift = [result[2][0][3] for result in output]
    return list(zip(lhs, rhs, support, confidence, lift))
output_DataFrame = pd.DataFrame(inspect(output), columns=['Left_Hand_Side', 'Right_Hand_Side', 'Support', 'Confidence', 'Lift'])

output_DataFrame.sort_values(by='Lift', ascending=False).head(20)