Excel + Python: From Data to Decisions
What happens when we combine the familiarity of Excel with the analytical power of Python? This project demonstrates how a simple Excel dataset can be transformed into meaningful business insights through automated calculations, sales analysis, performance indicators and dynamic visualisations. The entire video was created using Python, and the results are based on actual calculations. This is another step in our learning journey, exploring how programming can help us work smarter, make better decisions, increase productivity and ultimately thrive in an increasingly digital world.
Excel stores the data. Python reveals the patterns. People make the decisions.
Developed by Tryfon Papadopoulos
Main Python calculations
The following code is based on the actual Python script used to generate the video, reformatted for educational clarity.
Download the excel file: demo_sales.xlsx
Import data from Excel
import pandas as pd
sales = pd.read_excel(“demo_sales.xlsx”)
Calculate total revenue
total_revenue = sales[“Sales”].sum()
print(total_revenue)
Result: €7,500
Calculate monthly sales
monthly = sales.groupby(
“Month”, sort=False
)[“Sales”].sum()
print(monthly)
Calculate sales growth
growth = (
monthly.iloc[-1] / monthly.iloc[0] – 1
) * 100
print(f”{growth:.2f}%”)
Result: 50% growth between January and March.
Calculate sales by product
products = sales.groupby(“Product”)[“Sales”].sum()
print(products)
Calculate each product’s contribution to revenue
product_share = products / products.sum() * 100
print(product_share)
Identify the best-performing product
best_product = products.idxmax()
best_product_sales = products.max()
print(best_product)
print(best_product_sales)
Result: Alpha — €4,500 in revenue.
Complete analytical code
import pandas as pd
# Import Excel data
sales = pd.read_excel(“demo_sales.xlsx”)
# Calculate total revenue
total_revenue = sales[“Sales”].sum()
# Monthly sales analysis
monthly = sales.groupby(
“Month”, sort=False
)[“Sales”].sum()
# Sales growth
growth = (monthly.iloc[-1] / monthly.iloc[0] – 1) * 100
# Product performance
products = sales.groupby(“Product”)[“Sales”].sum()
# Product revenue contribution
product_share = products / total_revenue * 100
# Best-performing product
best_product = products.idxmax()
# Display business insights
print(f”Total revenue: EUR {total_revenue:,.2f}”)
print(f”Sales growth: {growth:.2f}%”)
print(f”Best product: {best_product}”)
print(“\nMonthly sales:”)
print(monthly)
print(“\nProduct revenue:”)
print(products)
print(“\nProduct contribution (%):”)
print(product_share)
—
The standalone code consolidates the calculations from the video generator and adds explicit variables for product contribution and best-performing product.
The key takeaway: With just a few lines of Python code, we can automate calculations that would otherwise require repeated manual work in Excel. As the volume of data increases, the benefits of this approach become even more significant.
—



Comments are closed.