AnalystPath

Apply Publisher Promotions to Book Prices

PandasMediumMid level~10 min

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.

books
book_idpublisherlist_price
1Lantern Press1000
2Cedar House50
3Lantern Press1200
4Maple Books500
promotions
publisherpercentage_off
Lantern Press10
Cedar House20

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 books

Solve 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

Related Pandas questions