In [ ]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
In [ ]:
df = pd.read_csv('customer.csv')
df.head()
Out[ ]:
Education Income Kidhome Marital_Status Recency MntFruits MntMeatProducts NumStorePurchases NumWebPurchases NumWebVisitsMonth
0 Graduation 58138.0 0 Single 58 88 546 4 8 7
1 Graduation 46344.0 1 Single 38 1 6 2 1 5
2 Graduation 71613.0 0 Together 26 49 127 10 8 4
3 Graduation 26646.0 1 Together 26 4 20 4 2 6
4 PhD 58293.0 1 Married 94 43 118 6 5 5
In [ ]:
#1. What is the distribution of customer education in this store?
#Explain which education type has the largest number of customers,
# which education type has the smallest number of customers? can use count plot and pie chart
df['Education'].value_counts()
Out[ ]:
count
Education
Graduation 101
PhD 44
Master 33
2n Cycle 17
Basic 5

In [ ]:
labels = df['Education'].value_counts().index.tolist()
labels
Out[ ]:
['Graduation', 'PhD', 'Master', '2n Cycle', 'Basic']
In [ ]:
values= df['Education'].value_counts().tolist()
values
Out[ ]:
[101, 44, 33, 17, 5]
In [ ]:
fig= plt.figure(figsize=(10,5))
plt.pie(values, labels=labels, autopct='%1.1f%%')
plt.title('Customer Education Distribution')
plt.show()
No description has been provided for this image
In [ ]:
#2. Please explore if the number of kids at consumers' home are associated with the income.
#Please describe your findings based on your analysis and visualization, can use point plot,
#sns.catplot(data=df, x='Kidhome', y='Income', kind='box', hue='Kidhome')
#plt.show()
sns.scatterplot(data=df, x='Kidhome', y='Income', hue='Kidhome')
plt.show()
No description has been provided for this image
In [ ]:
#3. In this grocery chain, customers can purchase both online and in-store.
#Are these purchases (i.e., online and in-store) related?
#If so, how they are related? Explain your results.
sns.scatterplot(data=df, x='NumStorePurchases', y='NumWebPurchases')
plt.show()
No description has been provided for this image
In [ ]:
# As a data scientist in this company, you want to know if
#married couples or singles have higher income?
#How to use visualization to explore this?  Briefly explain your results.
sns.kdeplot(data=df, x='Income', hue='Marital_Status', common_norm= False) #need common norm set to false for kde plot
plt.show()
No description has been provided for this image
In [ ]:
#Please find which education type of customers has
#the highest income? Explain your results.
sns.kdeplot(data=df, x='Income', hue= 'Education', common_norm= False)
plt.show()
No description has been provided for this image
In [ ]: