Chapter 2 · Section 4 practice

Feature Engineering and Modifying Tables

Work from question 1 to 10. Edit your Python box, click Run Code, review the result, then click Submit attempt. Reference answers unlock after all ten attempts are submitted. This records completion, not correctness. Each box runs independently. Progress is saved in this browser.

Submitted: 0 / 10

1. Calculate revenue

Warm-up. Create Revenue = Units × Price and print its values as a list.

Write your answer, then run it.

2. Total revenue

Warm-up. Calculate Revenue and print its total.

Write your answer, then run it.

3. Product cost

Warm-up. Add ProductCost to this table and print its list.

Write your answer, then run it.

4. Gross profit

Build your skills. Calculate GrossProfit from Revenue and ProductCost, then print its total.

Write your answer, then run it.

5. Order-size labels

Build your skills. Use a comprehension to label observed revenues >= 200 as Large and others as Standard. Print the list.

Write your answer, then run it.

6. Rename a column

Build your skills. Rename Units to Quantity and print the new column labels.

Write your answer, then run it.

7. Keep a smaller table

Build your skills. Drop Price into a new table and print both new and original column labels.

Write your answer, then run it.

8. The two largest orders

Challenge. Calculate Revenue, sort descending, and print labels of the top two records.

Write your answer, then run it.

9. Undefined margins

Challenge. Calculate Margin using only positive Revenue denominators. Print rounded margins as a list.

Write your answer, then run it.

10. Four direction labels

Challenge. Use loc assignments to label positive returns Up, zero Flat, negative Down, and missing Unknown. Print the list.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.