text_html_output_1.png
from sklearn.preprocessing import LabelEncoder

import pandas as pd

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
train = pd.read_excel('/kaggle/input/products/ABBREV_with_CLASS.xlsx')
train

train.isnull().sum()

Q1 = train['Protein_(g)'].quantile(0.25)
Q3 = train['Protein_(g)'].quantile(0.75)
IQR = Q3 - Q1
train = train[(train['Protein_(g)'] >= Q1 - 1.5 * IQR) & (train['Protein_(g)'] <= Q3 + 1.5 * IQR)]

from sklearn.preprocessing import LabelEncoder
labelencoder_Shrt_Desc = LabelEncoder()
train['Shrt_Desc'] = labelencoder_Shrt_Desc.fit_transform(train['Shrt_Desc'])
labelencoder_GmWt_Desc1 = LabelEncoder()
train['GmWt_Desc1'] = labelencoder_GmWt_Desc1.fit_transform(train['GmWt_Desc1'])
labelencoder_GmWt_Desc2 = LabelEncoder()
train['GmWt_Desc2'] = labelencoder_GmWt_Desc2.fit_transform(train['GmWt_Desc2'])

train.isnull().sum()

train['Ash_(g)'] = train['Ash_(g)'].fillna(train['Ash_(g)'].median())
train['Water_(g)'] = train['Water_(g)'].fillna(train['Water_(g)'].median())
train['Fiber_TD_(g)'] = train['Fiber_TD_(g)'].fillna(train['Fiber_TD_(g)'].median())
train['Sugar_Tot_(g)'] = train['Sugar_Tot_(g)'].fillna(train['Sugar_Tot_(g)'].median())
train['Calcium_(mg)'] = train['Calcium_(mg)'].fillna(train['Calcium_(mg)'].median())
train['Iron_(mg)'] = train['Iron_(mg)'].fillna(train['Iron_(mg)'].median())
train['Magnesium_(mg)'] = train['Magnesium_(mg)'].fillna(train['Magnesium_(mg)'].median())
train['Phosphorus_(mg)'] = train['Phosphorus_(mg)'].fillna(train['Phosphorus_(mg)'].median())
train['Potassium_(mg)'] = train['Potassium_(mg)'].fillna(train['Potassium_(mg)'].median())
train['Sodium_(mg)'] = train['Sodium_(mg)'].fillna(train['Sodium_(mg)'].median())
train['Zinc_(mg)'] = train['Zinc_(mg)'].fillna(train['Zinc_(mg)'].median())
train['Copper_mg)'] = train['Copper_mg)'].fillna(train['Copper_mg)'].median())
train['Manganese_(mg)'] = train['Manganese_(mg)'].fillna(train['Manganese_(mg)'].median())
train['Selenium_(µg)'] = train['Selenium_(µg)'].fillna(train['Selenium_(µg)'].median())
train['Vit_C_(mg)'] = train['Vit_C_(mg)'].fillna(train['Vit_C_(mg)'].median())
train['Thiamin_(mg)'] = train['Thiamin_(mg)'].fillna(train['Thiamin_(mg)'].median())
train['Riboflavin_(mg)'] = train['Riboflavin_(mg)'].fillna(train['Riboflavin_(mg)'].median())
train['Niacin_(mg)'] = train['Niacin_(mg)'].fillna(train['Niacin_(mg)'].median())
train['Panto_Acid_mg)'] = train['Panto_Acid_mg)'].fillna(train['Panto_Acid_mg)'].median())
train['Vit_B6_(mg)'] = train['Vit_B6_(mg)'].fillna(train['Vit_B6_(mg)'].median())
train['Folate_Tot_(µg)'] = train['Folate_Tot_(µg)'].fillna(train['Folate_Tot_(µg)'].median())
train['Folic_Acid_(µg)'] = train['Folic_Acid_(µg)'].fillna(train['Folic_Acid_(µg)'].median())
train['Food_Folate_(µg)'] = train['Food_Folate_(µg)'].fillna(train['Food_Folate_(µg)'].median())
train['Folate_DFE_(µg)'] = train['Folate_DFE_(µg)'].fillna(train['Folate_DFE_(µg)'].median())
train['Choline_Tot_ (mg)'] = train['Choline_Tot_ (mg)'].fillna(train['Choline_Tot_ (mg)'].median())
train['Vit_B12_(µg)'] = train['Vit_B12_(µg)'].fillna(train['Vit_B12_(µg)'].median())
train['Vit_A_IU'] = train['Vit_A_IU'].fillna(train['Vit_A_IU'].median())
train['Vit_A_RAE'] = train['Vit_A_RAE'].fillna(train['Vit_A_RAE'].median())
train['Retinol_(µg)'] = train['Retinol_(µg)'].fillna(train['Retinol_(µg)'].median())
train['Alpha_Carot_(µg)'] = train['Alpha_Carot_(µg)'].fillna(train['Alpha_Carot_(µg)'].median())
train['Beta_Carot_(µg)'] = train['Beta_Carot_(µg)'].fillna(train['Beta_Carot_(µg)'].median())
train['Beta_Crypt_(µg)'] = train['Beta_Crypt_(µg)'].fillna(train['Beta_Crypt_(µg)'].median())
train['Lycopene_(µg)'] = train['Lycopene_(µg)'].fillna(train['Lycopene_(µg)'].median())
train['Lut+Zea_ (µg)'] = train['Lut+Zea_ (µg)'].fillna(train['Lut+Zea_ (µg)'].median())
train['Vit_E_(mg)'] = train['Vit_E_(mg)'].fillna(train['Vit_E_(mg)'].median())
train['Vit_D_µg'] = train['Vit_D_µg'].fillna(train['Vit_D_µg'].median())
train['Vit_D_IU'] = train['Vit_D_IU'].fillna(train['Vit_D_IU'].median())
train['Vit_K_(µg)'] = train['Vit_K_(µg)'].fillna(train['Vit_K_(µg)'].median())
train['FA_Sat_(g)'] = train['FA_Sat_(g)'].fillna(train['FA_Sat_(g)'].median())
train['FA_Mono_(g)'] = train['FA_Mono_(g)'].fillna(train['FA_Mono_(g)'].median())
train['FA_Poly_(g)'] = train['FA_Poly_(g)'].fillna(train['FA_Poly_(g)'].median())
train['Cholestrl_(mg)'] = train['Cholestrl_(mg)'].fillna(train['Cholestrl_(mg)'].median())
train['GmWt_1'] = train['GmWt_1'].fillna(train['GmWt_1'].median())
train['GmWt_2'] = train['GmWt_2'].fillna(train['GmWt_2'].median())
train['Refuse_Pct'] = train['Refuse_Pct'].fillna(train['Refuse_Pct'].median())