Thursday, December 11, 2025

🎯 Project using Excel

 

🎯 Project: Sales Analysis from Excel Using pandas & matplotlib

πŸ“Œ Objective

  • Read sales data from Excel

  • Clean the data

  • Analyze monthly performance

  • Create graphs using matplotlib

  • Save processed data back to Excel


πŸ“‚ Sample Excel File (sales.xlsx)

Your Excel file may look like this:

MonthSales
Jan12000
Feb15000
Mar18000
Apr16000
May20000
Jun22000
Jul21000
Aug25000
Sep23000
Oct24000
Nov26000
Dec30000

Save as sales.xlsx.


Step 1: Read Excel File

import pandas as pd df = pd.read_excel("sales.xlsx") print(df)

Step 2: Check for missing values

print(df.isnull().sum())

Fill missing values with 0 (if any):

df["Sales"] = df["Sales"].fillna(0)

Step 3: Basic Analysis

✔ Total yearly sales

total_sales = df["Sales"].sum() print("Total Sales:", total_sales)

✔ Highest & lowest month

max_month = df.loc[df["Sales"].idxmax()] min_month = df.loc[df["Sales"].idxmin()] print("Best Month:", max_month["Month"], max_month["Sales"]) print("Worst Month:", min_month["Month"], min_month["Sales"])

πŸ“Š Step 4: Create Charts using matplotlib

Import library

import matplotlib.pyplot as plt

πŸ“ˆ Line Chart – Monthly Sales Trend

plt.figure(figsize=(10,5)) plt.plot(df["Month"], df["Sales"], marker='o') plt.xlabel("Month") plt.ylabel("Sales") plt.title("Monthly Sales Trend") plt.grid(True) plt.show()

πŸ“Š Bar Chart

plt.figure(figsize=(10,5)) plt.bar(df["Month"], df["Sales"]) plt.xlabel("Month") plt.ylabel("Sales") plt.title("Sales by Month") plt.show()

πŸ₯§ Pie Chart

plt.figure(figsize=(8,8)) plt.pie(df["Sales"], labels=df["Month"], autopct="%1.1f%%") plt.title("Sales Contribution by Month") plt.show()

πŸ“ Step 5: Save Results Back to Excel

with pd.ExcelWriter("sales_analysis.xlsx") as writer: df.to_excel(writer, sheet_name="Cleaned_Data", index=False) print("New Excel file saved!")

No comments:

Post a Comment

Python Viva Questions

  Basic Python Viva Questions 1. What is Python? Python is a high-level, interpreted, and object-oriented programming language used for w...