Chapter 1 quiz
Data Structures and Methods of Series
These questions review the examples in the companion slides. Choose an answer, then check the explanation.
Question 1
With the three-row table above, what does intro_table[[βPriceRegβ]] return?
- A Series with shape
(3,) - A DataFrame with shape
(3, 1) - A list of three prices
- A single price
Question 2
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 3
How many rows do aep.loc[β2017-01-01 01:00β:β2017-01-01 05:00β] and aep.iloc[0:5] return?
- 4 and 5
- 5 and 5
- 5 and 4
- 4 and 4
Question 4
weather[βdateβ].iloc[0] right after pd.read_csv is a β¦
strTimestampdatetime64int(days since 1970)
Question 5
Which object owns the title and y-axis label of one subplot?
- The DataFrame index
- The Axes
- The NumPy random generator
- The CSV file
Question 6
What does alist.mean() do?
- Prints
320.0 - Prints
[300, 100, 0, 200, 1000] - Raises
AttributeErrorβ lists have nomean - Returns
None
Question 7
dy.sum() and (dy + 1).isna().sum() give β¦
NaNand0β one hole poisons the sum, but adding 1 fills it48.28and1610β the sum skips holes, the addition keeps themNaNand1610β holes poison everything48.28and0β holes are treated as 0 everywhere
Question 8
For jan = sp500.loc[β2020β], do jan.loc[β2020-01-06β:β2020-01-08β] and jan.iloc[2:5] return the same rows?
- Yes β Jan 6, 7, 8 both times, but for opposite slicing rules
- No β
.locgives 2 rows,.ilocgives 3 - No β
.ilocincludes Jan 9 - They raise β you cannot mix index value and position
Question 9
msft.shift(1).iloc[0] is β¦
- The first close
NaN- The second close
- The last close
Question 10
In ax.hist(x, bins=50, density=True) the bars are scaled so that β¦
- The tallest bar has height 1
- The heights sum to 1
- The total area of the bars is 1
- The y-axis shows counts