AI & Machine Learning-Quiz: Pandas groupby & merge

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.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80%

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What 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())
Lösung zeigen

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.

Darum geht es in diesem Quiz

  • groupby() with sum(), size() and mean()
  • Group keys are sorted by default
  • transform() vs aggregation
  • Inner, left and outer merges and their row counts
  • Overlapping column names and the _x / _y suffixes

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.