- Executors
-
Learn
Learn Python Runnable examples, NumPy, pandas, and more Learn AI / Machine LearningNeural networks, ML and LLMs from scratch Learn C & C++ Pointers, memory, STL, and modern C++ Learn C#C# basics, OOP, LINQ, async, and .NET exercises Learn MatplotlibLine, bar, scatter and pie charts with live visualizers Learn RustOwnership, traits, error handling, and threads Learn GoSlices, interfaces, goroutines, and channels Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++ Coding for Kids Learn to code by playing!
- QuizzesNew
- ChallengesNew
- For TeachersNew
- Updates
- Buy me a coffee
AI & Machine Learning Pandas groupby & merge Quiz
Most feature engineering in pandas comes down to grouping rows and joining tables. This quiz tests groupby() with sum, size, mean and transform, and how the how argument of merge() changes the number of rows you get back.
Sample question
Question 1 of 10What does this print?
import pandas as pd
sales = pd.DataFrame({"city": ["Hanoi", "Hue", "Hanoi", "Hue", "Da Nang"],
"amount": [10, 5, 20, 15, 8]})
print(sales.groupby("city")["amount"].sum().to_dict())
Show the answer
B. {'Da Nang': 8, 'Hanoi': 30, 'Hue': 20} Each city's amounts are added (Hanoi 10 + 20, Hue 5 + 15) and, by default, the group keys come out sorted alphabetically, so Da Nang is first. Pass sort=False to keep first-seen order.
What this quiz covers
groupby()withsum(),size()andmean()- Group keys are sorted by default
transform()vs aggregation- Inner, left and outer merges and their row counts
- Overlapping column names and the
_x/_ysuffixes
Questions people ask
Do I need an account?
No. Anyone can play. Sign in to keep your XP, streak, badges and history.
Can I retake it?
Yes. Your best score is kept, and the questions and answers are shuffled each time.