Quiz di AI & Machine Learning: 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.

Medio 10 domande ~6 minuti Superato con il 80%

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 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())
Mostra la risposta

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.

Cosa copre questo 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

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.