image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df_cust = pd.read_csv('../input/customer-segmentation-dataset/Mall_Customers.csv')

df_cust.columns

df_cust.isna().sum()

df_cust.isnull().sum()

df_cust_male = df_cust[df_cust['Genre'] == 'Male']
df_cust_female = df_cust[df_cust['Genre'] == 'Female']

def boxplot(frame,x,y,*args):
    '''This function helps to plot the boxplot
    frame : dataframe to be used
    x     : dataframe column for x axis
    y     : dataframe column for y axis
    *args : to include more features like Title, palette, notch'''
    
    plt.figure(figsize=(8,8))
    bp=sns.boxplot(data=frame,x=x,y=y,palette=args[0],notch=args[1])
    medians = frame.groupby([x])[y].median().sort_values(ascending=False)
    vertical_offset = frame[y].median() * 0.01 # offset from median for display

    for xtick in bp.get_xticks():
        bp.text(xtick,medians[xtick] + vertical_offset,medians[xtick], 
                horizontalalignment='center',size='medium',color='blue',weight='semibold')
    plt.title(args[2])
    plt.grid()
    plt.show() 

df_genre = pd.DataFrame({'Genre': ['Female', 'Male'], 'Genre_code': [0, 1]})

df_cust = df_cust.merge(df_genre, on='Genre')

df_cust['Genre_code'].value_counts()