Mctaba Labs logo
BootcampData ScienceThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book CallApply

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
Mctaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • Coding Bootcamp in Nairobi
  • Data Science to AI Engineering
  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • Kids & Teens
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Data Science Guides
  • African Payments Reference
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Software & AI Studio
  • Our Work
  • Outcomes

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2026 Mctaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Data Science in Kenya
  3. Forecast a Shop's Stock from Till Data
Bonaventure OgetoBy Bonaventure Ogeto|Updated November 3, 2026

Last checked 3 November 2026

Forecast a Shop's Stock from Till Data

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.

In this article

  1. 1. The problem on the shelf
  2. 2. Step 1: a moving average
  3. 3. Step 2: weekday and month-end patterns
  4. 4. Step 3: a reorder point

The problem on the shelf

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.

Step 1: a moving average

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.

MethodCatchesMisses
7-day moving averageThe current levelWeekday and month-end swings
Weekday indexSaturday highs, Tuesday lowsA sudden change in level
Month-end flagSalary-week spikesHolidays 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.

Step 2: weekday and month-end patterns

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.

Step 3: a reorder point

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.

Where it goes wrong

  • Stock-outs hide demand. A day with zero sales may mean no stock, not no customers.
  • Promotions and holidays break the pattern. Mark them in a column.
  • Three months of history cannot show yearly seasons such as school opening.

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.

Key Takeaways

  • ✓A moving average gives the level. A weekday index gives the shape.
  • ✓Flag month-end days. Salary weeks change what customers buy.
  • ✓A reorder point is lead-time demand plus a safety buffer, written as one number.
  • ✓Zero sales can mean zero stock. Check before you trust a low day.

Frequently Asked Questions

Which forecasting method should a small shop start with?
A 7-day moving average shaped by a weekday index. It is easy to check, easy to explain and often close enough for stock decisions.
How much history do I need?
At least eight to twelve weeks to see weekday patterns. To see school-term or festive-season swings you need a year or more.
What is a reorder point?
The stock level at which you place an order. It equals the demand expected during the supplier lead time plus a safety buffer.
Do I need machine learning for this?
No. Start with averages and patterns. Move to a model only when a simple forecast keeps missing and you can say why.

Learn data science on African data

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

Need it live by next month? Our studio builds it

Related guides

  • Python for Data Science: Your First 30 Days
  • Analyse Your M-Pesa Statement in Python
  • Data Science in Kenya: The Career Map from First Line of Python to First Job

Keep reading

Pandas Tutorial Using a Nairobi Shop's Sales Data

A pandas tutorial on a kiosk sales file instead of the Titanic: load it, clean it, rank products and find the slow days.

Read more

The Statistics You Actually Need for Data Science

Five statistics ideas do most of the work in data jobs. Each one comes with a small worked example you can check on paper.

Read more

Data Engineering Basics: Build a Pipeline with Airflow and Docker

Start Airflow in Docker from the official compose file and build a three-task daily pipeline for shop sales: pull, clean, load.

Read more

Data Storytelling: Turning a Chart into a Decision

A chart is not the finish line. This guide shows the one-page memo, a simple way to pick a chart, and a before and after on made-up shop data.

Read more

Explore related topics

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

Tech Salary Data

Transparent salary data for tech roles in Africa and worldwide, updated regularly with real market research.

AI Skills & Tools

Practical AI knowledge for developers. Build your first agent, get good at RAG, and pick the right AI coding tools for real work.

Bonaventure Ogeto

Bonaventure Ogeto

Founder and CEO, Mctaba Labs

Software engineer for 8+ years. He runs a Nairobi studio that ships products on M-Pesa, WhatsApp and AI, and teaches what the studio ships. He holds a BSc in Mathematics and Computer Science.

More about the author