Chapter 2 · Section 3 practice

Grouped Tables, Joins and Reshaping

0 of 8 answered

These questions review the examples in the companion slides. Choose an answer, then check the explanation.

Question 1

Which operation returns one group mean aligned to each original row?

  • groupby(...).transform("mean")
  • groupby(...).mean()
  • groupby(...).size()
  • drop_duplicates()

Question 2

A stock appears in many months. Which columns should match its monthly sector table?

  • ticker alone
  • date alone
  • current row position
  • ticker and date together

Question 3

What does validate="many_to_one" require in a merge?

  • Equal row counts in both tables
  • No missing values anywhere
  • Unique matching-column combinations in the right table
  • Unique rows in both tables

Question 4

Which expression sets ticker and date as two row-index levels?

  • df["ticker"]
  • df.set_index(["ticker", "date"])
  • df.sort_values("date")
  • df.transpose()

Question 5

Which expression moves only the ticker index level into a column?

  • df.reset_index(level="ticker")
  • df.reset_index(drop=True)
  • df.drop(columns="ticker")
  • df.unstack("ticker")

Question 6

A return Series has index levels date and ticker. What does unstack("ticker") do?

  • Averages all stock returns
  • Deletes the date level
  • Replaces every missing return by zero
  • Moves ticker into columns, leaving dates as the row index

Question 7

Several universities share one country/year. Which operation can calculate their mean research score?

  • transpose()
  • set_index("country")
  • pivot_table(index=“country”, columns=“year”, values=“research”, aggfunc=“mean”)
  • pivot(index=“country”, columns=“year”, values=“research”)

Question 8

With pd.concat([a, b], axis=1), how are two Series matched?

  • By sorting their numeric values
  • By their row-index values
  • By position only
  • By their means