Pandasdrill

Level 4: Combining and reshaping Exercise 30 of 45 Pro

Merge on differently named keys

A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.

The task

Join `orders` to `products`, where the key is `product_id` in orders and `id` in products, keeping only matches. Add `line_total = qty * price` and return the columns `order_id`, `product` and `line_total`. Row order does not matter.

What this exercise teaches

left_on and right_on name the key in each table. Both key columns are kept in the merged result, and the inner join drops the order for a product that is not in the catalog.

A hint if you get stuck

Use left_on and right_on when the key columns have different names.

This exercise is part of Pro

Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Combining and reshaping