#5, First Floor, 4th Street , Dr. Subbarayan Nagar, Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to make association rules for grocery items using apriori algorithm in python?


To implement apriori algorithm for grocery items in python.


Grocery data.


Association between the items.


  Import the library.

  Load the data set.

  Build the model.

  Fit the grocery data.

  Make the association rules.

  Print the rules.

Sapmle Code

#import the library
import numpy as np
import pandas as pd
from apyori import apriori

#load the data
store_data = pd.read_csv(‘……/grocery.csv’)

#initialize a empty list
records = []
for i in range(0, 19):
records.append([str(store_data.values[i,j]) for j in range(0, 4)])

#applying apirori
association_rules = apriori(records, min_support=0.03, min_confidence=0.2, min_lift=3, min_length=2)

#make it as a data frame
df = pd.DataFrame(association_rules)

#create a excel file for results
final = df.to_excel(‘…/asso_rules.xlsx’)

for i in range(0,16):