<jupyter_start><jupyter_text><NAME> Data Science & Business Analytics Intern @ The Sparks Foundation Task - 3: Exploratory Data Analysis - Retail Store<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
data = pd.read_csv("SampleSuperstore.csv")
data.head()
data.shape
data.isnull().any()
data.nunique()
data.dtypes
# Check for duplicate values
data.duplicated().sum()
# Dropping duplicate values
data.drop_duplicates(inplace=True)
data.shape
data.corr()
sns.heatmap(data.corr(),annot=True)<jupyter_output><empty_output><jupyter_text>visualize the probability distribution of multiple samples in a single plot.<jupyter_code>plt.figure(figsize=(8,5))
sns.kdeplot(data['Sales'],color='red',label='Sales',shade=True,bw=20)
sns.kdeplot(data['Profit'],color='Black',label='Profit',shade=True,bw=20)
plt.xlim([-200,1000])
plt.legend()
# To find out  Sales and Profit generated by the Superstore

print('Sales:' ,data['Sales'].sum())
print('Profit:' ,data['Profit'].sum())<jupyter_output>Sales: 2296195.5903
Profit: 286241.4226<jupyter_text>Profit is more than that of sale but there are some areas where profit could be increased.<jupyter_code>plt.style.use('seaborn')
data.plot(kind = 'scatter', figsize = (10,5) , x = 'Sales', y='Profit', c = 'Discount' , s = 20 , fontsize = 16 , colormap = 'plasma')
plt.ylabel('TOTAL PROFITS', fontsize = 16)
plt.title('DEPENDENCY OF SALES AND PROFIT ON DISCOUNT' , fontsize = 16)
plt.show()<jupyter_output><empty_output><jupyter_text>The above Scatterplot depicts that less the discount more is the Profits Discount is effecting profit to a certain extent and after that point Profits has no relation with Discount<jupyter_code>fig,axs=plt.subplots(nrows=2,ncols=3,figsize=(20,10));

sns.countplot(data['Ship Mode'],ax=axs[0][0])
sns.countplot(data['Segment'],ax=axs[0][1])
sns.countplot(data['Quantity'],ax=axs[0][2])
sns.countplot(data['Category'],ax=axs[1][0])
sns.countplot(data['Region'],ax=axs[1][1])
sns.countplot(data['Discount'],ax=axs[1][2])

axs[0][0].set_title('Ship Mode')
axs[0][1].set_title('Segment')
axs[0][2].set_title('Quantity')
axs[1][0].set_title('Category')
axs[1][1].set_title('Region')
axs[1][2].set_title('Discount')


plt.tight_layout()
plt.figure(figsize=(20,10))
sns.countplot(data['Sub-Category'])
plt.title('Sub-Category')
plt.figure(figsize=(20,10))
sns.countplot(data['State'])
plt.xticks(rotation=90)
plt.title('State')<jupyter_output><empty_output><jupyter_text>Distribution of the data using the plot<jupyter_code>fig, axs = plt.subplots(ncols=2, nrows = 2, figsize = (20,15))
sns.distplot(data['Sales'], color = 'red',  ax = axs[0][0])
sns.distplot(data['Profit'], color = 'green',  ax = axs[0][1])
sns.distplot(data['Quantity'], color = 'orange',  ax = axs[1][0])
sns.distplot(data['Discount'], color = 'blue',  ax = axs[1][1])
axs[0][0].set_title('Sales')
axs[0][1].set_title('Profit')
axs[1][0].set_title('Quantity')
axs[1][1].set_title('Discount')
plt.show()<jupyter_output><empty_output><jupyter_text>Deal Analysis<jupyter_code>state = data['State'].value_counts()
state.plot(kind='bar',figsize=(20,10),color="maroon")
plt.ylabel(' Number of deals')
plt.xlabel('States')

plt.title('State Wise Dealings')
plt.show()
city = data['City'].value_counts()
city = city.head(50)
city.plot(kind='bar',figsize=(20,10),color="blue")
plt.ylabel(' Number of deals')
plt.xlabel('States')

plt.title('State Wise Dealings')
plt.show()<jupyter_output><empty_output><jupyter_text>Customer Analysis<jupyter_code># To check maximum Sales and Profit in each segment

data.groupby('Segment')['Sales','Profit'].sum().plot.bar()
plt.title('SALES AND PROFIT IN EACH SEGMENT')
plt.legend()
plt.show()<jupyter_output>C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:3: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
  This is separate from the ipykernel package so we can avoid doing imports until<jupyter_text>So the graph presents that Consumer segment is the one which has maximum buying capacity Also they give maximum profit to Superstore whereas Home Office purchases less and add less profit to business Now we will check Ship Mode Segment wise<jupyter_code># To check this we will use countplot 

sns.countplot(x='Segment' , hue='Ship Mode' , data=data)
plt.show()<jupyter_output><empty_output><jupyter_text>In each segment most of the transaction has been shipped under Standard Class<jupyter_code>data['Ship Mode'].value_counts()
shipmode = data.groupby(['Ship Mode'])[['Sales', 'Discount', 'Profit']].mean()
shipmode.plot.pie(subplots=True,
                     figsize=(18, 20), 
                     autopct='%1.1f%%', 
                     labels = shipmode.index)<jupyter_output><empty_output><jupyter_text>Profit and Discount is high in First ClassSales is high for Same day ship  PRODUCT ANALYSIS<jupyter_code>data.groupby('Category')['Sales','Profit'].sum().plot.bar()
plt.title('PROFIT AND SALES CATEGORY WISE')
plt.legend(loc = 1)
plt.show()
category = data.groupby(['Category'])[['Sales', 'Discount', 'Profit']].mean()
category
category.plot.pie(subplots=True, 
                     figsize=(18, 20), 
                     autopct='%1.1f%%', 
                     labels = category.index)<jupyter_output><empty_output><jupyter_text>This Bar Plot shows that Technology has given maximum sales subsequently Profit was also maximum. But not following this trend Furniture also had sales at great amount following with least amount of profit. So we have sub categories of Furniture which are Bookcases,Chairs,Furnishings and Tables.With this Bar Plot we can conclude that irrespective of high sales in Tables and Bookcases the store is incurring loss. This loss is affecting the whole of Furniture CategoryNow we need to check irrespective of high sales why are we incurring loss?<jupyter_code>sub_category = data.groupby(['Sub-Category'])[['Sales', 'Discount', 'Profit']].mean()
sub_category.head()
plt.figure(figsize = (15,15))
plt.pie(sub_category['Sales'], labels = sub_category.index, autopct = '%1.1f%%')
plt.title('Sub-Category Wise Sales Analysis', fontsize = 20)
plt.legend()
plt.xticks(rotation = 90)
plt.show()
plt.figure(figsize = (15,15))
plt.pie(sub_category['Discount'], labels = sub_category.index, autopct = '%1.1f%%')
plt.title('Sub-Category Wise Discount Analysis', fontsize = 20)
plt.legend()
plt.xticks(rotation = 90)
plt.show()
sub_category.sort_values('Profit')[['Sales','Profit']].plot(kind='bar',
                                                              figsize= (10,5),
                                                              label=['Avg Sales Price($)','Profit($)'])<jupyter_output><empty_output><jupyter_text>We concluded that despite of maximum Discount in Tables and Bookcases the store in incurring losses.Since we are having sales at max and Discount is also given,now we will check Correlation in between the two.<jupyter_code>data[data['Category'] == 'Furniture'].groupby('Sub-Category')['Sales','Profit'].sum().plot.bar()
plt.title('SALES AND PROFIT FURNITURE CATEGORY WISE ')
plt.legend(loc = 1)
plt.show()
# To check the probable reason of loss 

data[data['Category'] == 'Furniture'].groupby('Sub-Category')['Discount'].mean().plot.bar()
plt.title('DISCOUNT GIVEN IN FURNITURE CATEGORY')
plt.legend(loc = 0)
plt.show()<jupyter_output><empty_output><jupyter_text>From above Heatmap we concluded there is a Negative correlation in between Profit and Discountwhereas a Positive correlation between Profit and Sales  TOP PRODUCTS<jupyter_code># Now we will check the Top Products Sold

data.groupby('Sub-Category')['Sales'].sum().sort_values(ascending=False).plot.bar()
plt.show()<jupyter_output><empty_output><jupyter_text>With this we concluded that Phones,Chairs ,Storage,Tables and Binders are being sold at max consecutively.Whereas Fasteners,Labels and Envelopes were sold the least<jupyter_code>#To check the profit earned in all the  Sub-Categories

data.groupby('Sub-Category')['Profit'].sum().sort_values(ascending = False).plot.bar(color = 'brown')
plt.show()<jupyter_output><empty_output><jupyter_text>Here we saw Copiers ,Phones,Accessories are top profit giving products to the store. whereas Store is incurring losses due to Tables ,Bookcases and suppliers.  REGIONAL ANALYSIS<jupyter_code># To check maximum transactions made regionwise

data.Region.value_counts().plot.pie(autopct="%.1f%%")
plt.show()
region = data.groupby(['Region'])[['Sales', 'Discount', 'Profit']].mean()
region
region.plot.pie(subplots=True, 
                   figsize=(18, 20), 
                   autopct='%1.1f%%',
                   labels = region.index)
data.groupby('Region')['Sales','Profit'].sum().plot.bar()
plt.title('SALES AND PROFITS IN EACH REGION')
plt.legend()
plt.show<jupyter_output>C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
  """Entry point for launching an IPython kernel.
{'fraction_non_alphanumeric': 0.14464442493415278, 'fraction_numerical': 0.018327480245829676, 'mean_word_length': 5.7155490051584374, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '666334', 'license': 'Apache-2.0', 'n_tokens_mistral': 3218, 'n_tokens_neox': 2981, 'n_words': 740, 'path': 'Exploratory Data Analysis/EDA-Retail.ipynb', 'repo_name': 'Tech29-sam/tsf-tasks', 'size': '9120'}