Recommended resources
The freely available resources this lesson will direct you to.
- Probability of Mutually Exclusive Events With Venn Diagramswww.youtube.com
- Addition rule for probability | Probability and Statistics | Khan Academywww.youtube.com
- 2 Probability – STAT 500 | Applied Statisticsonline.stat.psu.edu
- 7.8 The Addition Rule for Probability - Contemporary Mathematics | OpenStaxopenstax.org
Hello! Last time, you defined a yes/no event on a row and estimated its probability by counting eligible rows. Now suppose you care about either of two events. Adding their shares seems natural—but if some rows satisfy both conditions, that calculation counts those rows twice.
This lesson develops one rule that handles both possibilities: events that cannot occur together and events that overlap. You will see the rule visually, derive it from counts, and check it in pandas.
What does “A or B” include?
Imagine selecting one observation and asking two yes/no questions about it. Let mean the first condition holds and mean the second holds. In probability, “ or ” includes observations where both hold. The notation distinguishes two useful events:
- , the union: , , or both.
- , the intersection: both and .
The words “or” and “and” refer to conditions on the same selected observation. That matters when you translate a question into column filters: you are not combining the chance of one row satisfying with the chance of a different row satisfying .
Watch this explanation before working through the pandas example. It builds the rule by counting objects in a Venn diagram rather than asking you to memorize a formula.
Addition rule for probability | Probability and Statistics | Khan Academy
Watch “Addition rule for probability” from Khan Academy for a visual account of why the overlap must be subtracted.
In the setup, note that the two conditions describe the same selected item; the speaker calls the blocks “cubes” later. Locate the overlap where an item meets both conditions. In the derivation, follow which items are counted twice when the two event counts are added. Finish with the disjoint case, where there is no overlap to subtract.
One addition rule, two cases
Every observation in belongs to one of three nonoverlapping regions: only, both and , or only. Adding and includes the “both” region once in each probability. Subtracting it once gives the general addition rule:
This is a counting correction, not an adjustment for uncertainty. It applies whether the events overlap or not.

Two events are mutually exclusive (or disjoint) if a single observation cannot satisfy both. Their intersection is empty, so . The general rule then simplifies to
For example, if one recorded category must be exactly one of alpha, beta, or gamma, the events “category is alpha” and “category is beta” are mutually exclusive. By contrast, “category is alpha” and “flag is True” might occur together. You must examine the event definitions—not just their individual probabilities—to decide whether the simplified rule applies.
A useful warning sign is a sum greater than : it cannot be the probability of an event, and unaccounted-for overlap may be the reason. But a sum below does not establish that the events are mutually exclusive. Overlap still needs to be checked.
From event counts to pandas masks
Consider twelve fully observed rows. Each has one category and a separate Boolean flag. We will treat selecting one of these rows uniformly at random as the experiment. Under that selection rule, each event’s probability is its count divided by ; the same fractions also describe the observed shares exactly.
import pandas as pd
df = pd.DataFrame({
"category": ["alpha"] * 4 + ["beta"] * 3 + ["gamma"] * 5,
"flag": [
True, True, False, False, # alpha
True, False, False, # beta
True, True, True, False, False # gamma
]
})
print(pd.crosstab(df["category"], df["flag"]))
The cross-tabulation makes the two conditions visible together:
| category | False |
True |
|---|---|---|
alpha |
2 | 2 |
beta |
2 | 1 |
gamma |
2 | 3 |
First, take to be “category is alpha” and to be “flag is True.” There are four rows and six rows. Two rows satisfy both, so the count satisfying at least one condition is , not .
Boolean pandas masks implement exactly those set operations: | means “or,” and & means “and.” Parenthesize each comparison when combining comparisons into a mask.
a = df["category"].eq("alpha")
b = df["flag"]
n = len(df)
count_a = a.sum()
count_b = b.sum()
count_both = (a & b).sum()
count_either = (a | b).sum()
print(count_a, count_b, count_both, count_either)
# 4 6 2 8
p_either_by_rule = (count_a + count_b - count_both) / n
p_either_direct = (a | b).mean()
print(p_either_by_rule, p_either_direct)
# 0.6666666666666666 0.6666666666666666
The direct mask and the addition rule agree because they count the same eight rows in different ways. You can make the double-counting particularly concrete by splitting all twelve rows into four regions:
regions = pd.Series({
"A only": (a & ~b).sum(),
"both": (a & b).sum(),
"B only": (~a & b).sum(),
"neither": (~a & ~b).sum()
})
print(regions)
# A only 2
# both 2
# B only 4
# neither 4
The union contains the first three regions: . The “neither” rows do not belong in it. Notice that calculating the overlap required counting (a & b) rows—not multiplying the two separate observed shares. No assumption about a relationship between the events is needed for the addition rule.
Now keep , but replace with : “category is beta.” Because a row has just one category, no row can be both alpha and beta.
c = df["category"].eq("beta")
print((a & c).sum()) # 0
print((a | c).mean()) # 0.5833333333333334
print(a.mean() + c.mean()) # 0.5833333333333333
Thus . The tiny difference in the final printed decimal digits is ordinary floating-point rounding; both calculations represent .
In a real dataset, preserve the denominator discipline from the previous lesson. If either condition is missing for some rows, decide which rows have enough information to classify both events before comparing their counts or means. All calculations above use the same twelve complete rows.
Key takeaways
To find the probability of or , include rows satisfying either condition, including those satisfying both. The universal rule is
Subtract the intersection because adding the two individual probabilities counts it twice. When the events are mutually exclusive, the intersection is impossible and the subtraction term is zero. In pandas, (a | b) counts the union directly, while (a & b) lets you check its overlap and verify the rule.
Next, you will turn from “either event” to probabilities involving both events, including what changes when you know that one event has already occurred.