Python ile Market Basket Analysis
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School


| TID | İşlem |
|---|---|
| 1 | biyografi, tarih |
| 2 | kurgu |
| 3 | biyografi, şiir |
| 4 | kurgu, tarih |
| 5 | biyografi |
| ... | ... |
| 75000 | kurgu, şiir |
Birlikte sık alınan ürünleri bul.
Bu bulgularla öneriler oluştur.
| TID | İşlem |
|---|---|
| 11 | kurgu, biyografi |
| 12 | kurgu, biyografi |
| 13 | tarih, biyografi |
| ... | ... |
| 19 | kurgu, biyografi |
| 20 | kurgu, biyografi |
| ... | ... |
import pandas as pd
# Load transactions from pandas.
books = pd.read_csv("datasets/bookstore.csv")
# Print the header
print(books.head(2))
TID Transaction
0 biography, history
1 fiction
Tazeleme için Pandas Hızlı Başvuru sayfasına bak.
# Split transaction strings into lists.
transactions = books['Transaction'].apply(lambda t: t.split(','))
# Convert DataFrame into list of strings.
transactions = list(transactions)
# Print the first transaction.
print(transactions[0])
['biography', 'history']
# Count the number of transactions that contain biography and fiction.
transactions.count(['biography', 'fiction'])
218
# Count the number of transactions that contain fiction and poetry.
transactions.count(['fiction', 'poetry'])
5357

Python ile Market Basket Analysis