Binning with cut
cut puts numbers into labelled bins.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
df["grade"] = pd.cut(df["score"], bins=[0, 74, 84, 100], labels=["C", "B", "A"])
print(df[["name", "grade"]])Result
name grade 0 Ada A 1 Kofi B 2 Amina A 3 Tunde C
Exercise
Bins.
pd.(s, bins=3)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.