Chapter 2 · Section 1 practice
DataFrame Foundations
These questions review the examples in the companion slides. Choose an answer, then check the explanation.
Question 1
Which selection returns a Series from df?
df["AEP"]df[["AEP"]]df.loc[:, ["AEP"]]df.head()
Question 2
A table has 5 rows and 3 numeric columns. How many values does df.mean(axis=0) return?
- 5
- 15
- 1
- 3
Question 3
After df.set_index("ticker"), how can ticker become a column again?
dropna()mean()reset_index()sort_index()
Question 4
After sorting rows by price, what happens to their index values?
- They remain in chronological order
- Each index value stays with its original row
- They are automatically replaced by 0, 1, 2
- They are deleted
Question 5
Two numeric frames overlap on one row index value and two column names. Where can their sum have observed values?
- At the two shared row/column combinations
- At every cell in either frame
- At no cells
- Only at the first row position
Question 6
Ticker and date are already columns. Which export avoids an extra column for the incidental row index?
df.to_csv("prices.csv", index=True)df.sort_index()df.reset_index(drop=True)df.to_csv("prices.csv", index=False)