SQL (SQLite), Python (pandas, scipy)

The Cost of a Late Package: Olist Delivery Analysis

Using 99,441 real orders from Olist, the largest department store on Brazilian marketplaces, I measured how late deliveries affect customer reviews and traced where the delays come from. Late orders were only 6.8% of volume but were tied to 27.6% of all 1 and 2 star reviews.

At a glance: tool
SQL (SQLite), Python (pandas, scipy)
Dataset size
27.6% of low reviews tied to just 6.8% of orders
More likely to get a 1-2 star review when late
Of low reviews tied to just 6.8% of orders
Of sellers caused half of all late orders
SQL (SQLite), Python (pandas, scipy) dashboard preview for the The Cost of a Late Package: Olist Delivery Analysis case study

Problem

Olist, the largest department store on Brazilian marketplaces, shows every customer an estimated delivery date at checkout. I wanted to know how much missing that promise costs in customer satisfaction, and whether late deliveries are a system-wide problem or concentrated in specific sellers and shipping routes.

Approach

Data: 99,441 real anonymized Olist orders (2016 to 2018) across 8 related tables: orders, items, customers, sellers, products, reviews, payments, and category translations. 1. Loaded the raw CSVs into a SQLite database with Python and ran data quality checks before any analysis (duplicate reviews, multi-seller orders, missing dates and categories). 2. Built one clean order-level view in SQL using CTEs, joins, and window functions. 3. Wrote 9 SQL queries covering delivery KPIs, monthly trends, review scores by days late, shipping routes, seller concentration, estimate accuracy, and product categories. 4. Used Python (scipy) to test whether the link between lateness and reviews is statistically significant, then estimated its business impact.

Key Technical Challenges & How I Solved Them

  1. Challenge

    Duplicate reviews

    Solution

    547 orders had more than one review. I used ROW_NUMBER() partitioned by order to keep only the most recent review, so no order was counted twice.

  2. Challenge

    Orders split across sellers

    Solution

    1,278 orders included items from multiple sellers, which would double count them. I limited seller and route analysis to single-seller orders so each order maps to one seller and one route.

  3. Challenge

    Choosing the right statistical test

    Solution

    Star ratings are ordinal, so a t-test would be misleading. I used chi-square with Cramer's V for effect size, Mann-Whitney U, and Spearman correlation instead, all significant at p < 0.001.

Code Behind the Analysis

Cleaning reviews with a window functionSQL
1WITH latest_review AS (
2 SELECT
3 order_id,
4 review_score,
5 ROW_NUMBER() OVER (
6 PARTITION BY order_id
7 ORDER BY review_answer_timestamp DESC
8 ) AS rn
9 FROM reviews
10)
11SELECT order_id, review_score
12FROM latest_review
13WHERE rn = 1;
Finding the sellers behind half of late ordersSQL
1WITH seller_late AS (
2 SELECT seller_id,
3 SUM(CASE WHEN days_vs_estimate > 0 THEN 1 ELSE 0 END) AS late_orders
4 FROM order_facts
5 WHERE seller_count = 1
6 GROUP BY seller_id
7),
8ranked AS (
9 SELECT seller_id, late_orders,
10 ROW_NUMBER() OVER (ORDER BY late_orders DESC) AS seller_rank,
11 SUM(late_orders) OVER (ORDER BY late_orders DESC
12 ROWS UNBOUNDED PRECEDING) AS running_late,
13 SUM(late_orders) OVER () AS total_late
14 FROM seller_late
15)
16SELECT MIN(seller_rank) AS sellers_causing_50pct_of_late
17FROM ranked
18WHERE running_late >= 0.5 * total_late;
Testing lateness vs. reviewsPython
1df["late"] = df["days_vs_estimate"] > 0
2df["low_review"] = df["review_score"] <= 2
3
4# Chi-square: are 1-2 star reviews independent of lateness?
5table = pd.crosstab(df["late"], df["low_review"])
6chi2, p_value, _, _ = stats.chi2_contingency(table)
7cramers_v = (chi2 / table.to_numpy().sum()) ** 0.5
8
9# Relative risk of a low review when late
10late, on_time = df[df["late"]], df[~df["late"]]
11relative_risk = late["low_review"].mean() / on_time["low_review"].mean()
12
13# Mann-Whitney U: right test for ordinal 1-5 star scores
14_, mw_p = stats.mannwhitneyu(late["review_score"],
15 on_time["review_score"], alternative="less")
View full source

Results

Late delivery is the clearest driver of bad reviews. On-time orders got a 1 or 2 star review 9.3% of the time. Late orders did 62.4% of the time, 6.7 times more likely (chi-square p < 0.001, Cramer's V 0.40). Every extra day late makes it worse. Average review score fell from 4.29 on time to 3.29 at 1 to 3 days late, 2.10 at 4 to 7 days, and 1.70 at 8+ days. Only 6.8% of orders arrived late, yet they are associated with roughly 3,400 extra low reviews, 27.6% of all 1 and 2 star reviews. The problem is concentrated. Just 98 of 2,948 sellers (3.3%) account for half of all late orders. By route, Sao Paulo to Rio de Janeiro missed the promise 14.3% of the time across 8,048 orders, and Sao Paulo to Maranhao 19.1%. Estimates are padded, but unevenly. 74% of orders arrived 8 or more days early, while the routes above were still late. Late rates also spiked to 12.4% in November 2017 (Black Friday month) and 19.0% in March 2018. Not every low review is about delivery. Office furniture had the lowest score (3.64) and still scored only 3.76 when delivered on time, pointing to a product issue instead. 1. Set delivery estimates by route instead of using one blanket buffer. Tighten estimates on routes that arrive weeks early and add time to Sao Paulo to North/Northeast lanes and Sao Paulo to Rio. 2. Start a delivery performance program with the 98 sellers behind half of all late orders. 3. Notify customers as soon as an order is going to be late. Scores drop sharply after day 3, so early communication matters most. 4. Plan carrier capacity ahead of peak periods like Black Friday. Note: the data covers 2016 to 2018, and the review impact is an association, not proof of cause.

Code

SQL queries and Python analysis script

github.com/pavleristic2001/olist-delivery-analysis

View on GitHub

Want to talk through this work?

Get in touch