← Quiz: groupby and merge: all 10 questions
Quiz: groupby and merge · Question 7 of 10
What does this print? (code)
What does this print?
import pandas as pd
df = pd.DataFrame({"branch": ["CSE", "ECE", "CSE", "ECE", "IT"], "cgpa": [8.0, 7.0, 9.0, 8.0, 9.5]})
print(df.groupby("branch")["cgpa"].mean().to_dict())
- A.{'CSE': 8.5, 'ECE': 7.5, 'IT': 9.5}
- B.{'CSE': 17.0, 'ECE': 15.0, 'IT': 9.5}
- C.{'CSE': 2, 'ECE': 2, 'IT': 1}
- D.{'branch': 8.3}
Answer & explanation
Correct answer: {'CSE': 8.5, 'ECE': 7.5, 'IT': 9.5}
mean gives the average per branch; sum would give 17.0 and 15.0.
Can you get the rest right without peeking?
Take the timed Quiz: groupby and merge quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →