Frequency Tables
value_counts with normalize gives shares and crosstab counts pairs.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df["country"].value_counts(normalize=True).round(2))
print(pd.crosstab(df["country"], df["score"] > 80))Result
country NG 0.75 GH 0.25 Name: proportion, dtype: float64 score False True country GH 1 0 NG 1 2
Exercise
Pair counts.
pd.(a, b)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.