Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from mlxtend.frequent_patterns import apriori
- from mlxtend.frequent_patterns import association_rules
- df = pd.read_excel('Vendas.xls', sheet_name='VENDAS')
- keys = df[['PRODUTO', 'Cod', 'Soma de QTDITEPDD']]
- basket = keys.groupby(['Cod', 'PRODUTO'])['Soma de QTDITEPDD']\
- .sum().unstack().reset_index().fillna(0)\
- .set_index('Cod')
- def encode_units(x):
- if x <= 0:
- return 0
- if x >= 1:
- return 1
- basket_sets = basket.applymap(encode_units)
- frequent_itemsets = apriori(basket_sets)
- rules = association_rules(frequent_itemsets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement