We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

String Length

I often find myself needing to check the length of a string column. For example, a username should be at least 5 characters long, but perhaps no more than 20.

df = df[(df["username"].str.len() >= 5) & (df["username"].str.len() < 20)]

Alternatively, a movie_id might always be a fixed length of 32 characters:

df = df[df["movie_id"].str.len() == 32]

Assignment

Complete the clean_device_ids function. It accepts a DataFrame with a fixed device_id column, then trims whitespace, removes empty strings, filters out IDs shorter than 3 characters, and returns a cleaned DataFrame.