Pandasdrill

Level 4: Combining and reshaping Exercise 62 of 102

Outer merge: what is missing on each side

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

`books` and `bank` should list the same transactions. Return the references that appear in only one of the two tables, as a DataFrame with the columns `ref` and `source`, where `source` is "books" for a reference that is only in `books` and "bank" for one that is only in `bank`. Row labels and row order do not matter.

What this exercise teaches

An outer merge with an indicator is the standard reconciliation tool: one pass shows what is missing on either side. A left merge would only ever find the references missing from the bank.

A hint if you get stuck

how="outer" keeps the rows of both tables, and indicator=True adds a _merge column that says left_only, right_only or both. Keep the rows that are not both and translate the label.

Try it now, free, no account needed

Your first 8 exercises on Pandasdrill are free. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro unlocks every exercise, timed mode and the certificate.

Open this exercise

More exercises in Combining and reshaping