✦ AI Use Case

Python in Excel
Data Science Inside the Spreadsheet

Running Pandas, Scikit-learn, and Matplotlib directly inside Excel cells — bringing full data science capability to business analysts without IT involvement.

🏚 Industry: Manufacturing / Supply Chain
🛠 Tool: Python in Excel (Microsoft 365)
Impact: ML model in Excel, zero IT deployment

Business Problem

Scenario: Inventory Demand Forecasting

A supply chain analyst needs to forecast demand for 200 SKUs across 6 warehouses. The data lives in Excel. The data science team built a Python forecasting model — but deploying it requires IT involvement, a Python environment, and a process the analyst cannot run independently. Every forecast update requires a 3-day turnaround.

Python in Excel — Live Code

Using Python in Excel (powered by Anaconda in the cloud), the analyst runs the full forecasting pipeline inside a spreadsheet cell — no separate environment needed.

Step 1: Load Excel Table Data & Fit Forecast Model
import pandas as pd
from prophet import Prophet

# xl() reads directly from the Excel Table named SalesHistory
df = xl("SalesHistory[#All]", headers=True)
df.columns = ["ds", "y"]
df["ds"] = pd.to_datetime(df["ds"])

model = Prophet(yearly_seasonality=True)
model.fit(df)

future = model.make_future_dataframe(periods=90)
forecast = model.predict(future)

# Returns dynamic array back to Excel
forecast[["ds","yhat","yhat_lower","yhat_upper"]].tail(90)
Step 2: Render Chart Directly in Excel Cell
import matplotlib.pyplot as plt, matplotlib
matplotlib.use("Agg")

fig, ax = plt.subplots(figsize=(10, 4))
ax.plot(df["ds"], df["y"], label="Actual", color="#6366f1", linewidth=1.5)
ax.plot(forecast["ds"], forecast["yhat"],
        label="Forecast", color="#06b6d4", linewidth=2, linestyle="--")
ax.fill_between(forecast["ds"],
                forecast["yhat_lower"], forecast["yhat_upper"],
                alpha=0.15, color="#06b6d4")
ax.set_title("90-Day Demand Forecast", fontsize=13, fontweight="bold")
ax.legend(); ax.grid(True, alpha=0.2)
plt.tight_layout()
plt.show()  # Renders as image directly in the Excel cell
How xl() works: The built-in xl() function reads named Excel Tables, ranges, or cell references directly into Python as Pandas DataFrames. Results written back to the sheet become dynamic arrays — automatically refreshing when source data changes.

Measured Outcomes

200
SKUs forecasted automatically
0
IT tickets required
90
Day rolling forecast window
18%
Reduction in stockout events