Pandasdrill

Level 2: Cleaning Exercise 17 of 45 Pro

Rename columns and replace a placeholder

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

Rename the columns `Qty` to `qty`, `Unit Price` to `unit_price` and `Region` to `region`. Then replace the text "N/A" in the region column with "Unknown". Return the table.

What this exercise teaches

rename takes a dict from old to new names and leaves other columns alone. replace on the region column then swaps the placeholder text for a real label, so later groupings do not treat "N/A" as a region.

A hint if you get stuck

rename(columns={old: new}) changes labels, and Series.replace(old, new) swaps values.

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 Cleaning