text_plain_output_1.png
import pandas as pd

pd.set_option('display.max_columns', 50)
pd.set_option('display.max_rows', 50)

train = pd.read_csv('/kaggle/input/marketing-dsg/train.csv')
test = pd.read_csv('/kaggle/input/marketing-dsg/test.csv')
train_prior_order = pd.read_csv('/kaggle/input/marketing-dsg/train_prior_order.csv')
test_prior_order = pd.read_csv('/kaggle/input/marketing-dsg/test_prior_order.csv')
products = pd.read_csv('/kaggle/input/marketing-dsg/products.csv')
departments = pd.read_csv('/kaggle/input/marketing-dsg/departments.csv')
sample_submission = pd.read_csv('/kaggle/input/marketing-dsg/sample_submission.csv')

prior_order = train_prior_order.append(test_prior_order)

prior_order.shape

prior_order = pd.merge(prior_order, products, on='product_id', how='left')
prior_order = pd.merge(prior_order, departments, on='department_id', how='left')

prior_order_unique = prior_order.drop_duplicates('order_id')

product_count = prior_order.groupby('product_id').count()[['order_id']].reset_index().rename(columns={'order_id': 'product_count'})
product_count.sort_values('product_count', ascending=False, inplace=True)
product_count = pd.merge(product_count, products, on='product_id', how='left')
product_count = pd.merge(product_count, departments, on='department_id', how='left')

product_count.head(10)