Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Data Visualization using Python/Sales Performance Analysis.ipynb
3074 views
Kernel: Python 3 (ipykernel)

Case Study: Sales Performance Analysis Objective To analyze and visualize the sales performance of a company over the past year using Matplotlib and Seaborn.

Dataset

  • Month: The month of the year.

  • Sales: Total sales in dollars.

  • Profit: Total profit in dollars.

  • Region: The region where the sales were made.

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # Step 1: Load the data # Read the sales data from the Excel file df = pd.read_excel("sales_data.xlsx") # Step 2: Data Overview # Display the first few rows of the dataset to understand its structure print("First 5 rows:") print(df.head()) # Generate summary statistics for numerical columns print("\nData Summary:") print(df.describe()) # Check for missing values in the dataset print("\nMissing Values:") print(df.isnull().sum()) # Step 3: Data Cleaning (if required) # Remove any missing values from the dataset df.dropna(inplace=True) # Drop missing values if any # Step 4: Data Analysis # Analyze sales trends by month monthly_sales = df.groupby("Month")["Sales"].sum().sort_index() # Visualizing Monthly Sales Trend plt.figure(figsize=(10, 5)) plt.plot(monthly_sales.index, monthly_sales.values, marker='o', linestyle='-', color='b') plt.xlabel("Month") plt.ylabel("Total Sales") plt.title("Monthly Sales Trend") plt.grid() plt.show() # Step 5: Region-wise sales distribution # Using boxplot to understand sales distribution across different regions plt.figure(figsize=(8, 5)) sns.boxplot(x="Region", y="Sales", data=df) plt.title("Sales Distribution by Region") plt.show() # Step 6: Sales vs Profit Analysis # Scatter plot to visualize the relationship between sales and profit across regions plt.figure(figsize=(6, 6)) sns.scatterplot(x=df['Sales'], y=df['Profit'], hue=df['Region']) plt.xlabel("Sales") plt.ylabel("Profit") plt.title("Sales vs Profit Analysis") plt.show() # Step 7: Conclusion # Summarizing key insights from the analysis print("Key Takeaways:") print("1. Identify seasonal trends in sales.") print("2. Understand regional variations in sales.") print("3. Analyze the relationship between sales and profit.")
First 5 rows: Month Sales Profit Region 0 Jan 23000 3000 East 1 Feb 15000 4800 North 2 Jun 27000 6500 North 3 Sep 30000 4000 West 4 Jul 15000 5200 East Data Summary: Sales Profit count 1000.000000 1000.000000 mean 24131.000000 5468.100000 std 5471.908331 1429.165807 min 15000.000000 3000.000000 25% 21000.000000 4500.000000 50% 23000.000000 5200.000000 75% 27000.000000 6500.000000 max 35000.000000 8000.000000 Missing Values: Month 0 Sales 0 Profit 0 Region 0 dtype: int64
Image in a Jupyter notebookImage in a Jupyter notebookImage in a Jupyter notebook
Key Takeaways: 1. Identify seasonal trends in sales. 2. Understand regional variations in sales. 3. Analyze the relationship between sales and profit.