text_html_output_1.png
from itertools import chain

import os

import pandas as pd

import pandas as pd

DATAFRAME_PATH = '/kaggle/input/productcategorization2/image_taxonomy_and_description.csv'
IMAGE_DIRECTORY_PATH = '/kaggle/input/productcategorization2/new_images/new_images'

images_list = [int(iter.split('.')[0]) for iter in os.listdir(IMAGE_DIRECTORY_PATH)]
df = pd.read_csv(DATAFRAME_PATH)
df1 = df.copy()
df1 = df1[df1['product_id'].isin(images_list)]
df1.reset_index(drop=True, inplace=True)
df1.drop({'long_description', 'short_description'}, axis=1, inplace=True)
unique_labels_having_one_cat = sorted(list(set(chain.from_iterable(df['taxonomy'].apply(lambda x: [iter for iter in x.split('|') if iter.count('>') == 0]).to_list()))))
unique_labels_having_two_cat = sorted(list(set(chain.from_iterable(df['taxonomy'].apply(lambda x: [iter for iter in x.split('|') if iter.count('>') == 1]).to_list()))))
unique_labels_having_three_cat = sorted(list(set(chain.from_iterable(df['taxonomy'].apply(lambda x: [iter for iter in x.split('|') if iter.count('>') == 2]).to_list()))))

df1.shape

df1.head()