<jupyter_start><jupyter_text>THE SPARKS FOUNDATION DATA SCIENCE AND BUSINESS ANALYTICS JUNE'21 AUTHOR : <NAME> Task: 3 Exploratory Data Analysis - Retail**Objective** : ● Perform ‘Exploratory Data Analysis’ on dataset ‘SampleSuperstore’                          ●As a business manager, try to find out the weak areas where you can work to make more profit.                          ● What all business problems you can derive by exploring the data?  Importing Libraries<jupyter_code># Importing all libraries required
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Data collection<jupyter_code>data = pd.read_csv('SampleSuperstore.csv')
data<jupyter_output><empty_output><jupyter_text>Data Analysis<jupyter_code># getting the shape of data set
data.shape
# getting the attributes
data.columns
data.head()
data.tail()
data.info()
data.describe()
#checking null values in dataset

data.isnull().sum()
data.duplicated().sum()   #check no. of duplicates
data.drop_duplicates()
data.nunique()  #unique values<jupyter_output><empty_output><jupyter_text>Checking Profits in different states<jupyter_code>print('total no. of states are : ',  data['State'].nunique())
print(data['State'].value_counts())
States_profit = data.groupby('State').sum()['Profit'].sort_values(ascending=False).reset_index()
#sorting the states by their profits in descending order(from highest to lowest profit.)
plt.figure(figsize=(15,10))
plt.title('Most Profitable States')
sns.barplot(x = 'State',y = 'Profit', data = States_profit.head(15)) #printing first 15 highest profitable states
plt.xticks(rotation = 60 , fontsize = 15) #rotating the labels on x-axis 
plt.yticks(fontsize = 15) 
plt.show()
# total states are 49 , we found the most profitable 15 states so Now, lets find out lowest profitable 15 states from remaining 34 states

plt.figure(figsize=(15,10))
plt.title('Least Profitable States')
sns.barplot(x = 'State',y = 'Profit', data = States_profit.tail(15)) #printing 15 lowest profitable states
plt.xticks(rotation = 60 , fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()<jupyter_output><empty_output><jupyter_text>**Here we can predict that, State with highest profit is California and State with lowest profit is Texas**  Checking Profits in different Cities<jupyter_code>print('Total no. of Cities are : ',  data['City'].nunique())
print(data['City'].value_counts())
city_profit = data.groupby('City').sum()['Profit'].sort_values(ascending = False).reset_index()
#grouping the cities to check the profits in each city and sorting them in descending order from highest to lowest profit.
plt.figure(figsize=(15,10))
plt.title('Most Profitable Cities')
# sns.barplot(x = city_profit['City'][:15],y = city_profit['Profit'][:15])
sns.barplot(x = 'City',y = 'Profit',data = city_profit.head(15))
plt.xticks(rotation = 60 , fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()<jupyter_output><empty_output><jupyter_text>**Here we can predict that, City with highest profit is New York and city with lowest profit is Philadelphia.**  Checking Sales in different states<jupyter_code>State_sales = data.groupby('State').sum()['Sales'].sort_values(ascending = False).reset_index()
plt.figure(figsize=(15,10))
plt.title('States with highest sales rate')
sns.barplot(x = 'State', y = 'Sales', data = State_sales.head(15)) 
plt.xticks(rotation = 60 , fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()
plt.figure(figsize=(15,10))
plt.title('States with lowest sales rate')
sns.barplot(x = 'State', y = 'Sales', data = State_sales.tail(15)) 
plt.xticks(rotation = 60 , fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()<jupyter_output><empty_output><jupyter_text>**So from this we can predict that the state having highest sales rate is California and State having lowest sales rate is North Dakota**  Sales vs Profit<jupyter_code>Sales = data.groupby('State').sum()['Sales'].nlargest(n=15) #top 15 states with highest sales
Profits = data.groupby('State').sum()['Profit'].nlargest(n=15) #top 15 states with highest sales

Sales.plot(kind='bar', figsize=(10,5),fontsize = 15, color = 'lightgreen')
Profits.plot(kind='bar', figsize=(10,5),fontsize = 15 , color='Purple')
plt.xlabel('States',fontsize = 15)
plt.ylabel('Total sales and profit',fontsize = 15)
plt.title("Sales vs Profit",fontsize = 15)
plt.show()<jupyter_output><empty_output><jupyter_text>**From above plot, we can conclude that California and New York has highest sales and Profits**  Profit and sales on Different Categories<jupyter_code>data['Category'].value_counts()
plt.figure(figsize=(8,5))
sns.countplot(x='Category', data = data)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()<jupyter_output><empty_output><jupyter_text>Checking the correlations<jupyter_code>data.corr()
plt.figure(figsize=(10,5))
sns.heatmap(data.corr(), annot=True)
plt.show()
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("Dependancy of Sales,Profits and Discounts",fontsize = 16)

plt.show()
sns.lineplot(x='Sales',y='Profit',data = data)
plt.show()
sns.lineplot(x='Discount',y='Profit',data = data)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13795045045045046, 'fraction_numerical': 0.023085585585585586, 'mean_word_length': 6.350344827586207, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '659475', 'license': 'Apache-2.0', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1741, 'n_words': 471, 'path': 'Task_3_Exploratory_Data_Analysis_Retail.ipynb', 'repo_name': 'BhoomiVarshney/The_Sparks_Foundation_Tasks', 'size': '5337'}