image_output_1.png
import os

import pandas as pd

product_name_dictionary = {}
product_name_dictionary2 = {}
for dirname, _, filenames in os.walk('/kaggle/input/learnplatform-covid19-impact-on-digital-learning/engagement_data/'):
    for filename in filenames:
        engagement_data_path = os.path.join(dirname, filename)
        df_temp = pd.read_csv(engagement_data_path, dtype={'lp_id': str})
        df_temp = df_temp.fillna(0)
        df_temp = df_temp.groupby(by='lp_id', as_index=False).sum()
        for index, row in df_temp.iterrows():
            if row['lp_id'] in product_name_dictionary.keys():
                product_name_dictionary[row['lp_id']] += row['pct_access']
                product_name_dictionary2[row['lp_id']] += row['engagement_index']
            else:
                product_name_dictionary[row['lp_id']] = row['pct_access']
                product_name_dictionary2[row['lp_id']] = row['engagement_index']

def dict_val(x):
    return x[1]
sorted_product_name_dictionary = sorted(product_name_dictionary.items(), key=dict_val, reverse=True)

product_df = pd.read_csv('/kaggle/input/learnplatform-covid19-impact-on-digital-learning/products_info.csv', dtype={'LP ID': str})

i = 1
name_count = []
for key, val in sorted_product_name_dictionary[:11]:
    product_name = product_df[product_df['LP ID'] == key]['Product Name'].values
    if product_name != None:
        name_count.append((product_name[0], val))
        i += 1

def dict_val(x):
    return x[1]
sorted_product_name_dictionary2 = sorted(product_name_dictionary2.items(), key=dict_val, reverse=True)

i = 1
name_count = []
for key, val in sorted_product_name_dictionary2[:11]:
    product_name = product_df[product_df['LP ID'] == key]['Product Name'].values
    if product_name != None:
        name_count.append((product_name[0], val))
        print(str(i) + ' :' + product_name[0])
        i += 1