Last checked
Total sales per day, smooth them with a 7-day moving average, measure how each weekday and the month-end differ from the average, and multiply that pattern by recent sales to forecast the week. A reorder point is the demand over the supplier lead time plus a safety buffer.
McTaba runs coding and data bootcamps in Kenya. This guide is written to be useful whether or not you ever join one.
Picture a shopkeeper in Nakuru standing at the fridge on Friday afternoon. Milk is almost gone. The supplier delivers in three days. If she orders too little, Saturday's customers walk to the next kiosk. If she orders too much, the packets expire. A forecast answers one question: how many will I sell before the next delivery?
This is a project on our data science career map. It needs only pandas and numpy. The sales below are generated by code, so they are made up. Use your own till export when you have one. If pandas is new, do the pandas tutorial on a shop's sales first.
import numpy as np
import pandas as pd
rng = np.random.default_rng(3)
days = pd.date_range("2026-08-01", "2026-10-31")
base = np.array([18, 16, 17, 19, 26, 34, 22]) # Mon to Sun
units = base[days.day_of_week] + rng.poisson(3, len(days))
units = units + np.where(days.day >= 28, 8, 0) # month-end
s = pd.Series(units, index=days, name="units")
Imagine this is packets of milk sold each day over three months. Friday and Saturday sell more, and the last days of the month sell more again, when salaries land.
ma7 = s.rolling(7).mean()
print(ma7.tail(1).round(1).item())
Each point averages the last seven days, so every weekday counts once. The weekend peak melts into a steady level. That level is your starting forecast: "about this many a day, give or take".
The weakness is that a flat average ignores Saturday. It would tell you to expect the same on Tuesday and Saturday. We fix that next.
| Method | Catches | Misses |
|---|---|---|
| 7-day moving average | The current level | Weekday and month-end swings |
| Weekday index | Saturday highs, Tuesday lows | A sudden change in level |
| Month-end flag | Salary-week spikes | Holidays and school terms |
Our Data Science to AI Engineering programme covers time-series features like these in phase 3.
Get weekly developer tips
Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.
No spam. Unsubscribe anytime.
df = s.to_frame()
df["weekday"] = df.index.day_name()
df["month_end"] = df.index.day >= 28
wk_index = df.groupby("weekday")["units"].mean() / df["units"].mean()
print(wk_index.round(2))
print(df.groupby("month_end")["units"].mean().round(1))
A weekday index of 1.4 means that day sells about 40 percent above the average day. Below 1 means quieter than average. The second print compares month-end days with the rest.
Now forecast the next week: take the level from the last 28 days and shape it with the weekday index.
level = s.tail(28).mean()
future = pd.date_range("2026-11-01", periods=7)
fc = pd.Series(
[level * wk_index[d.day_name()] for d in future],
index=future).round()
print(fc)
This is simple on purpose. The last 28 days include a month-end, so the level runs a little high for early November. Splitting the month-end effect out is a good extension. Check the forecast against what actually sold, and keep a running list of misses.
A reorder point is the stock level at which you place the next order. It has two parts: what you expect to sell while you wait for delivery, and a buffer for a busier-than-expected spell.
lead_days = 3
lead_demand = fc.head(lead_days).sum()
daily_std = s.tail(28).std()
safety = 1.65 * daily_std * np.sqrt(lead_days)
reorder_point = round(lead_demand + safety)
print(reorder_point)
For example, the factor 1.65 is a common textbook choice for a buffer that covers demand about 95 times in 100. A shop that hates stock-outs can raise it. A shop with perishables may lower it. Statistics for this kind of reasoning are in our statistics guide for data science.
Write the result on a card for the fridge: "Reorder at this many packets." That one number is the product of the project, and the shopkeeper can use it without opening Python.
Next, the same daily table can feed a dashboard or a WhatsApp reminder. Show it well with data storytelling, and refresh it daily with an Airflow and Docker pipeline. If you want a tool like this built for your shop or chain, see our custom software service. To learn the full method with mentors, read about the Data Science to AI Engineering programme: 5 months full time or 8 months part time, starting 11 January 2027.
KES 140,000
Data Science to AI Engineering: 5 months full time or 8 months part time, hybrid in Nairobi. Fraud, credit and M-Pesa data from Week 1, and every model deployed. Starts 11 January 2027.
See the Data Science programme