Practice / strings dates nulls

Clean Phone Digits

medium

The Daily Grind imported phone numbers from three different systems, each formatted its own way. Normalise them to bare digits.

contacts

Your task: return id and digits — the phone with every non-digit character removed.

Assign your answer DataFrame to result. Row order doesn't matter.

contactsinput DataFrame

Schema
columntype
idlong
phonestring
Sample rows
idphone
1(555) 123-4567
2555.987.6543
Expected output shape
iddigits· 2 rows
Hint

F.regexp_replace("phone", "[^0-9]", "") deletes every character that is NOT a digit. Alias it digits and select it alongside id.

Lesson refresher

This problem builds on Strings, Dates & Nulls (~8 min). Pop it open in a new tab if you want a quick recap.

Loading editor…
Hit Run to execute your code and see the output here.