🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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())
  1. A.{'CSE': 8.5, 'ECE': 7.5, 'IT': 9.5}
  2. B.{'CSE': 17.0, 'ECE': 15.0, 'IT': 9.5}
  3. C.{'CSE': 2, 'ECE': 2, 'IT': 1}
  4. 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 →