Count rows per group
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
Return the number of orders each rep has, as a Series indexed by rep in alphabetical order.
What this exercise teaches
groupby("rep").size() counts the rows in each group. value_counts gives the same numbers but sorts them by count, largest first, so the order would not be alphabetical without sort_index().
A hint if you get stuck
count() or size() per group gives the number of rows. groupby sorts the keys for you.
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.