Group means as a flat table
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 average `units` per product as a DataFrame with two columns, `product` and `units`, and a plain 0, 1, 2 index.
What this exercise teaches
By default the group keys move into the index and a single column comes back as a Series. as_index=False, or reset_index(), turns the result back into an ordinary table with product as a column.
A hint if you get stuck
as_index=False keeps the group key as a regular column. reset_index() after the fact does the same.
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.