Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views3 pages

Superstore - Colab

Fjjj

Uploaded by

rtxtr92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Superstore - Colab

Fjjj

Uploaded by

rtxtr92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Double-click (or enter) to edit

from google.colab import drive


drive.mount('/content/drive')

Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive",

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Load the dataset


file_path = '/content/drive/MyDrive/Assignments/Rahat/superstore.csv' # replace with your file's path
df = pd.read_csv(file_path, encoding='latin-1') # Try reading the file with 'latin-1' encoding

# Display the first few rows of the dataframe


print(df.head())

Row ID Order ID Order Date Ship Date Ship Mode Customer ID \


0 1 CA-2016-152156 11/8/2016 11/11/2016 Second Class CG-12520
1 2 CA-2016-152156 11/8/2016 11/11/2016 Second Class CG-12520
2 3 CA-2016-138688 6/12/2016 6/16/2016 Second Class DV-13045
3 4 US-2015-108966 10/11/2015 10/18/2015 Standard Class SO-20335
4 5 US-2015-108966 10/11/2015 10/18/2015 Standard Class SO-20335

Customer Name Segment Country City ... \


0 Claire Gute Consumer United States Henderson ...
1 Claire Gute Consumer United States Henderson ...
2 Darrin Van Huff Corporate United States Los Angeles ...
3 Sean O'Donnell Consumer United States Fort Lauderdale ...
4 Sean O'Donnell Consumer United States Fort Lauderdale ...

Postal Code Region Product ID Category Sub-Category \


0 42420 South FUR-BO-10001798 Furniture Bookcases
1 42420 South FUR-CH-10000454 Furniture Chairs
2 90036 West OFF-LA-10000240 Office Supplies Labels
3 33311 South FUR-TA-10000577 Furniture Tables
4 33311 South OFF-ST-10000760 Office Supplies Storage

Product Name Sales Quantity \


0 Bush Somerset Collection Bookcase 261.9600 2
1 Hon Deluxe Fabric Upholstered Stacking Chairs,... 731.9400 3
2 Self-Adhesive Address Labels for Typewriters b... 14.6200 2
3 Bretford CR4500 Series Slim Rectangular Table 957.5775 5
4 Eldon Fold 'N Roll Cart System 22.3680 2

Discount Profit
0 0.00 41.9136
1 0.00 219.5820
2 0.00 6.8714
3 0.45 -383.0310
4 0.20 2.5164

[5 rows x 21 columns]

Perform Correlation Analysis

# Check for correlation between 'Discount' and 'Sales'


correlation = df['Discount'].corr(df['Sales'])

# Plot a scatter plot to visualize the correlation


plt.figure(figsize=(10, 6))
sns.scatterplot(x='Discount', y='Sales', data=df)
plt.title(f'Scatter Plot of Discount vs Sales (Correlation: {correlation:.2f})')
plt.xlabel('Discount')
plt.ylabel('Sales')
plt.show()

# Print the correlation value


print(f'The correlation between discount and sales is: {correlation:.2f}')

The correlation between discount and sales is: -0.03

Create a Function to Calculate Net Revenue

def calculate_net_revenue(sales, discount):


"""
Calculate the net revenue after applying a discount.

Parameters:
sales (float/pd.Series): The sales amount
discount (float/pd.Series): The discount percentage

Returns:
float/pd.Series: The net revenue
"""
net_revenue = sales * (1 - discount)
return net_revenue

# Add net revenue to the dataframe


df['Net_Revenue'] = calculate_net_revenue(df['Sales'], df['Discount'])

# Display the updated dataframe with net revenue


print(df[['Sales', 'Discount', 'Net_Revenue']].head())

Sales Discount Net_Revenue


0 261.9600 0.00 261.960000
1 731.9400 0.00 731.940000
2 14.6200 0.00 14.620000
3 957.5775 0.45 526.667625
4 22.3680 0.20 17.894400
keyboard_arrow_down Findings
The correlation analysis between the coefficient of correlation for discount and sales will be carried out. This c

A positive value implies that sales amount is likely to move up with an increase in discount
An increase in discount implies a likely down ward movement in sales amount hence a negative value
This indicates that either there is a weak or no linear correlation between discount and sales as illustrated by t
Ploting scatter plot and looking at thé correlation coefficient gives us; preliminary conclusions about discount-s
Finally, I have created a function named calculate_net_revenue that calculates the net income based on applying pe

The discount and sales correlation analysis will yield a correlation coefficient that demonstrates the relationshi

A positive figure indicates the likelihood of increased sale amounts with increased discounts
A growing discount could mean falling sale figures; hence, we can expect a negative figure
An amount which is close to zero suggests weak or no linear interdependence between discounts and sales.

By drawing up scatterplots and calculating coefficients for these two variables we can get some first indications

Lastly, I wrote a function called calculate_net_revenue whose purpose was to get net revenues by applying increase

You might also like