<jupyter_start><jupyter_text>__BLACK FRIDAY SALE__Motivation:Last year my friend got shifted to US. From her I got to hear a lot on excitement of black friday sale around christmas. Just got curious to analyse the amount of benefitts it would impose both for sellers and buyers, hence thought of exploring this data which I came across in kaggle.__DATASET:__ BlackFriday.csv from kaggle__BUSINESS QUESTIONS__Will be following CRISP_DM steps in this project. I would like derive insights on below points with the help of this data set.Question 1: Top spender of black friday, listing the top 10 spending usersQuestion 2: Understanding age group distribution of spendersQuestion 3: Which are the most popular products, list the top 10 amonst themQuestion 4: Observing correlation between Purchase  and (Gender, Age, Occupation, City_Category, Stay_In_Current_City_Years, Marital_Status, Product_Category_x)<jupyter_code>#Having all nessacary libraries imported
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

#Understanding Data
BF_CompleteData = pd.read_csv('./BlackFriday.csv')
BF_CompleteData.head()
BF_CompleteData.info()
rows = BF_CompleteData.shape[0] #Total rows in data set
cols = BF_CompleteData.shape[1] #Total columns in data set
print("Number of rows: {}".format(rows))
print("Number of columns: {}".format(cols))<jupyter_output>Number of rows: 537577
Number of columns: 12<jupyter_text>__Preparing Data__Here we do data wrangling to make it ready for further exploration:Checking columns with missing & dealing with it and do impact analysis of removing these values.One-Hot Encoding for Categorical variables (Gender, Age, City_Category, Stay_in_curent_City_Years).<jupyter_code>#Missing values in data set
BF_CompleteData.isnull().sum()
#BF_CompleteData.describe()<jupyter_output><empty_output><jupyter_text>From above data we can infer that two columns have missing values 'Product_Category_2' and 'Product_Category_3' meaning shoppers dint purchage anything in these 2 categories. Hence I would replace it with numerical value 0<jupyter_code>BF_CompleteData.fillna(0)
#One-Hot encoding of following categorical features:Age, City_Category, Gender,Stay_in_curent_City_Years
label = LabelEncoder()
BF_CompleteData['Age_oneencode'] = label.fit_transform(BF_CompleteData['Age'].astype(str))
BF_CompleteData['City_Category_oneencode'] = label.fit_transform(BF_CompleteData['City_Category'].astype(str))
BF_CompleteData['Gender_oneencode'] = label.fit_transform(BF_CompleteData['Gender'].astype(str))
BF_CompleteData['Stay_in_curent_City_Years_oneencode'] = label.fit_transform(BF_CompleteData['Stay_In_Current_City_Years'].astype(str))

#Question 1: Top spender of black friday, listing the top 10 spending users
# total purchase done by each user
user_total_purchase = BF_CompleteData.groupby('User_ID')['Purchase'].sum()
#Top 10 purchasers
top10_users = user_total_purchase.nlargest(10)
plt.figure(figsize = (10,6))
top10_users.plot(kind = 'bar')<jupyter_output><empty_output><jupyter_text>This is a helpful insight where seller can identify their top customers and study the pattern of the purchases made by them. It will help sellers to make usefull business changes in areas eg: product's price , kind of products sold etc.  Also to make the users regular customers special user benefit programs can be launched.<jupyter_code>#Question 2: Understanding age group distribution of spenders
plt.figure(figsize = (10,6))
sns.countplot(BF_CompleteData['Age'])
#Plotting age distribution based on gender
plt.figure(figsize = (10,6))
sns.countplot(BF_CompleteData['Age'], hue = BF_CompleteData['Gender'])<jupyter_output><empty_output><jupyter_text>Above plot shows 2 pattern:1. Maximum users shopping on black friday belong to age group of '26-35', '36-45', '18-25'. These group people are mostly collage goers and people with job hence have more shopping requirements.2. Also pattern shows that males tend to shop more as compared to females, reason can be infered as electronic goods are most preferred products to be bought during black friday sales seeing majority of male customers for it.<jupyter_code># Question 3 :Which are the most popular products, list the top 10 amonst them
plt.figure(figsize=(10,6))
#total purchase per product
product_purchase_count = BF_CompleteData.groupby('Product_ID')['Purchase'].count()
#product_purchase_count
top10_prod = product_purchase_count.nlargest(10)
#top10_prod.plot('pie')
top10_prod.plot('barh')<jupyter_output><empty_output><jupyter_text>The above analysis can help the sellers to keep in stock their high selling products, stocking smilar products and derive further insights like promotions of low selling products etc.<jupyter_code>BF_CompleteData.describe()
#Question 4: Observing correlation between Purchase and (Gender, Age, Occupation, City_Category, Stay_In_Current_City_Years, Marital_Status, Product_Category_x)
correlation_data = BF_CompleteData[['Gender_oneencode', 'Age_oneencode', 'Occupation', 'City_Category_oneencode', 
    'Stay_in_curent_City_Years_oneencode', 'Marital_Status', 'Product_Category_1', 'Product_Category_2', 'Product_Category_3', 'Purchase']]
correlation_data.corr()
plot_colormap = plt.cm.inferno
plt.figure(figsize=(10,8))
plt.title('Correlation between features of black friday sale: Gender, Age, Occupation, City_Category, Stay_In_Current_City_Years, Marital_Status, Product_Category_x vs Purchase', y=1.05, size=15)
sns.heatmap(correlation_data.corr(),linewidths=0.1,vmax=1.0, 
            square=True, cmap=plot_colormap, linecolor='white', annot=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08043554618897085, 'fraction_numerical': 0.01563048823322796, 'mean_word_length': 7.412112259970458, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '471206', 'license': 'CNRI-Python', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1649, 'n_words': 560, 'path': 'BlackFridaySale.ipynb', 'repo_name': 'kriti88/DataScience-NanoDegree', 'size': '5694'}