Apply Publisher Promotions to Book Prices
Problem
An online bookstore runs promotions by publisher. Two DataFrames are loaded from CSV: `books` (`book_id`, `publisher`, `list_price`) where list_price is in whole shekels, and `promotions` (`publisher`, `percentage_off`) giving a discount percentage for some publishers.
Compute the `checkout_price` for every book as list_price minus list_price * percentage_off / 100, using integer (floor) division to match the SQL twin. Books whose publisher has no promotion keep their list_price unchanged. Return a DataFrame with columns `book_id`, `checkout_price`, `publisher`, ordered by `book_id`.
Input data
Example rows — the live problem includes the full dataset.
| book_id | publisher | list_price |
|---|---|---|
| 1 | Lantern Press | 1000 |
| 2 | Cedar House | 50 |
| 3 | Lantern Press | 1200 |
| 4 | Maple Books | 500 |
| publisher | percentage_off |
|---|---|
| Lantern Press | 10 |
| Cedar House | 20 |
Expected output
Your answer should return 4 rows with the columns book_id, checkout_price, publisher.
Starter code (Pandas (Python))
import pandas as pd
def checkout_prices(books, promotions) -> pd.DataFrame:
# Your code here
return booksSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock