Chapter 1 · Section 2 practice

Value Transformations and Cleaning

0 of 6 answered

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

Question 1

price.where((price >= 50), other=0) returns …

  • Same length; prices ≥ 50 kept, the rest set to 0
  • Only the prices ≥ 50 (shorter Series)
  • Same length; prices ≥ 50 set to 0
  • Prices < 50 dropped, the rest set to 0

Question 2

dy.sum() and (dy + 1).isna().sum() give …

  • NaN and 0 — one hole poisons the sum, but adding 1 fills it
  • 48.28 and 1610 — the sum skips holes, the addition keeps them
  • NaN and 1610 — holes poison everything
  • 48.28 and 0 — holes are treated as 0 everywhere

Question 3

pd.Series([1, np.nan, np.nan, 4]).ffill() fills the two missing rows with …

  • 1, 1
  • 2, 3
  • 0, 0
  • 2.5, 2.5

Question 4

s.quantile(0.8) == 21 tells you …

  • 21 is the sample 80th-percentile cut point; ties and interpolation affect exact counts
  • 80 % of the values equal 21
  • The mean is 21 with 80 % confidence
  • 21 % of the values are ≤ 80

Question 5

Which call returns [40, 30, 10] — no 20 at all?

  • dlist.drop_duplicates()
  • dlist.drop_duplicates(keep="first")
  • dlist.drop_duplicates(keep="last")
  • dlist.drop_duplicates(keep=False)

Question 6

pd.cut(price, bins=4) has a first upper boundary of 700, with 19,990 of 20,000 prices at or below it. How full is that bin?

  • About 25 % — bins are equal-count
  • Over 99 % — bins are equal-width and the data are skewed
  • Exactly 50 %
  • Empty — the first bin starts below the minimum