Age bands with cut
A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.
The task
Label each age with a band using the edges 0, 18, 35, 60 and 120 and the labels "child", "young adult", "adult" and "senior". Each band includes its upper edge (18 is a child, 35 is a young adult). Return a Series.
What this exercise teaches
With bins [0, 18, 35, 60, 120] the intervals are (0, 18], (18, 35], (35, 60] and (60, 120]. right=False would flip which band a boundary age like 18 falls into.
A hint if you get stuck
cut takes a list of bin edges. By default each bin includes its right edge.
This exercise is part of Pro
Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.