market basket analysis python code example

Example: Market basket analysis Python

import pandas as pdimport numpy as npcolumns = ['user_id', 'item_id', 'rating', 'timestamp']df = pd.read_csv('ml-100k/u.data', sep='\t', names=columns)columns = ['item_id', 'movie title', 'release date', 'video release date', 'IMDb URL', 'unknown', 'Action', 'Adventure',          'Animation', 'Childrens', 'Comedy', 'Crime', 'Documentary', 'Drama', 'Fantasy', 'Film-Noir', 'Horror',          'Musical', 'Mystery', 'Romance', 'Sci-Fi', 'Thriller', 'War', 'Western']movies = pd.read_csv('ml-100k/u.item', sep='|', names=columns, encoding='latin-1')movie_names = movies[['item_id', 'movie title']]combined_movies_data = pd.merge(df, movie_names, on='item_id')combined_movies_data = combined_movies_data[['user_id','movie title']]combined_movies_data.head()