text_html_output_2.png text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

traindf = pd.read_csv('/kaggle/input/bigmart-sales-data/Train.csv')
testdf = pd.read_csv('/kaggle/input/bigmart-sales-data/Test.csv')

traindf.dtypes

traindf.describe().round(3)

traindf.isna().sum()

df = pd.concat([traindf, testdf], axis=0)
df.shape
df.isnull().sum()

df = df.dropna(subset=['Item_Weight', 'Outlet_Size', 'Item_Outlet_Sales'])

df_itemwt = df.Item_Weight.value_counts().reset_index().rename(columns={'index': 'Item_Weight', 'Item_Weight': 'Number_Of_Items'})
df_itemwt_sorted = df_itemwt.sort_values(by='Number_Of_Items', ascending=False).head(20).reset_index(drop=True)
df_itemwt_sorted

df.loc[df['Item_Fat_Content'] == 'LF', 'Item_Fat_Content'] = 'Low Fat'
df.loc[df['Item_Fat_Content'] == 'low fat', 'Item_Fat_Content'] = 'Low Fat'
df.loc[df['Item_Fat_Content'] == 'reg', 'Item_Fat_Content'] = 'Regular'
df['Item_Fat_Content'].value_counts()

df_itemfat = df.Item_Fat_Content.value_counts().reset_index().rename(columns={'index': 'Fat_Content', 'Item_Fat_Content': 'Number_of_items'})
df_itemfat

item_type_visibility = df[['Item_Type', 'Item_Visibility']].sort_values(by='Item_Visibility', ascending=False).reset_index()[['Item_Type', 'Item_Visibility']]

item_type_visibility = item_type_visibility[item_type_visibility['Item_Visibility'] != 0]

item_type_visibility_average = item_type_visibility.groupby('Item_Type').mean().sort_values(by='Item_Visibility', ascending=False).reset_index()
item_type_visibility_average

item_type_count = df.groupby('Item_Type').count()['Item_Identifier'].reset_index().rename(columns={'Item_Identifier': 'Number_Of_Items'}).sort_values(by='Number_Of_Items', ascending=False)
item_type_count

plt.figure(figsize=(25, 8))
sns.barplot(data=item_type_count, x='Item_Type', y='Number_Of_Items', palette='autumn')
plt.ylabel('Type of Item')
plt.xlabel('Number of Items')
plt.title('Items and their types')
plt.show()