Topic 4 of 5 · 5 min read
Wrong joins, filters and averages
Goal: Spot a double count, a dropped segment or an average of averages in an AI analysis and ask for the specific fix.
Four errors cause most wrong chat analyses: joins that multiply rows, filters that quietly drop a segment, averages of averages, and units that were never made equal. Each one gives a clean, confident number that is wrong.
Check yourself · 1 of 3
An order has two payment rows. After the assistant joins orders to payments and sums order amounts, what goes wrong?
Why it matters
These errors do not cause crashes or warnings. The code runs. The table looks tidy. The only symptom is a figure that is too high, too low or about the wrong people. You catch them by knowing what each one looks like and asking one specific question.
The four errors
- Double counting after a join. You have an orders table and a payments table. An order with two payments joins to two rows, so its amount counts twice. Symptom: total revenue is higher than your finance system shows. Check: row count before and after the join, and whether the join key is unique. The pandas guide to merging explains how repeated keys multiply rows.
- Rows lost silently. A filter, a
dropnaor a join that keeps only matches can remove a whole segment. Symptom: one region or month is missing from the table. Check: the list of groups before and after, and the row count at each step. - Average of averages. Store A has 10 orders averaging 100. Store B has 90 orders averaging 50. The average of 100 and 50 is 75, but the average per order is 55. Symptom: a group average that ignores group size. Check: ask for the total divided by the total, not the mean of group means.
- Mixed units. Some prices are in euros and some in dollars, or durations in minutes and hours, or numbers stored as text. Symptom: a few absurd values pull the average. Check: ask for the minimum, maximum and unit of each money or time column.
A related trap is Simpson's paradox, where each group trends one way and the combined data trends the other. If a headline conflicts with a breakdown, ask for the breakdown.
Before and after
Before: "Total revenue is 1.9 million." Your finance report says 1.2 million.
After: You ask: "How many rows were in the orders table, and how many after joining payments? Is order ID unique in each table?" The assistant finds 4,812 orders became 6,900 rows. You say: "Total payments per order first, then join, so each order appears once. Recompute revenue and show the row count after the join."
The revised total is 1.2 million and matches finance.
How to ask for the fix
Name the error and the remedy. "Weight the average by the number of orders." "Show which regions were removed by that filter and include them." "Deduplicate on order ID before summing."
What goes wrong
- Asking "is this right?" The assistant says yes. Ask a specific check instead.
- Fixing the symptom. Dividing by two to match finance leaves the cause in place.
- Not comparing with a known total. One known figure is the cheapest test.
Examples
Average of averages
| Store | Orders | Average order |
|---|---|---|
| A | 10 | 100 |
| B | 90 | 50 |
The assistant reports "average order value 75", the mean of 100 and 50. The true value is (10 x 100 + 90 x 50) divided by 100 orders, which is 55. Ask: "Weight by the number of orders and show the calculation."
A segment that vanished
The assistant's table lists North, East and South, but you also sell in West. Ask: "Which regions were in the file, and which were removed? Show the row count after each step." The answer reveals a join that kept only regions present in a second table.
Key points
- A join on a key that repeats multiplies rows, so amounts get counted more than once.
- Filters, dropna and match-only joins can remove a whole segment without any warning.
- An average of group averages ignores group size; ask for total divided by total.
- Mixed units, such as euros with dollars or minutes with hours, distort averages.
- Compare the result with one total you already trust, and ask for row counts at every step.
- Ask for the specific fix by name rather than asking whether the answer is right.
Common mistakes
- Asking the assistant whether its answer is correct instead of asking for a specific check.
- Not comparing the result with a total you already know from another source.
- Adjusting the final number by hand instead of fixing the join or filter that caused the error.
- Averaging group averages without weighting by group size.
Check yourself · 2 of 3
Store A has 10 orders averaging 100. Store B has 90 orders averaging 50. What is the correct average order value across both stores?
Check yourself · 3 of 3
A revenue table from an AI analysis shows North, East and South, but you also sell in West. What is the best next question?
Practice items, not counted towards your mastery.
Start here
- Data analysis with ChatGPT (OpenAI Help Center) (opens in a new tab)DocsFree
How ChatGPT reads uploaded files, runs Python for you and what limits apply to file size and types.
- Create and edit files with Claude (opens in a new tab)DocsFree
How Claude runs code on your files and hands back new files you can download and check.
- Python Data Science Handbook (opens in a new tab)BookFree
A free book that shows what grouping, merging and filtering do, so you can read the steps an assistant ran.
More for this topic
- Merge, join, concatenate and compare (pandas) (opens in a new tab)DocsFree
The official pandas guide to joins, including how a join on a repeated key multiplies rows.
- Simpson's paradox (Wikipedia) (opens in a new tab)ArticleFree
Real examples of a group-level average pointing the opposite way to the overall average.