Pandasdrill

Level 2: Cleaning Exercise 15 of 45 Pro

Pull numbers out of codes

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

Each code looks like ORD-2024-0153. Extract the final group of digits as an integer (so 0153 becomes 153) and return it as a Series.

What this exercise teaches

str.extract with one capture group returns a DataFrame whose column 0 holds the match. Anchoring with $ picks the last digits rather than the year, and astype(int) turns "0153" into 153.

A hint if you get stuck

A regular expression like (\d+)$ captures the digits at the end of the string. str.extract returns a DataFrame, one column per group.

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