0
0
Pandasdata~10 mins

str.strip() for whitespace in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to remove whitespace from the start and end of the 'Name' column in the DataFrame.

Pandas
df['Name'] = df['Name'].str.[1]()
Drag options to blanks, or click blank then click option'
Alower
Bsplit
Cstrip
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'split' instead of 'strip' which splits strings into lists.
Using 'replace' which replaces characters but doesn't specifically remove whitespace at ends.
2fill in blank
medium

Complete the code to remove whitespace only from the right side of the 'City' column.

Pandas
df['City'] = df['City'].str.[1]()
Drag options to blanks, or click blank then click option'
Arstrip
Bstrip
Clstrip
Dtrim
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'strip' which removes whitespace from both sides.
Using 'lstrip' which removes whitespace from the left side.
3fill in blank
hard

Fix the error in the code to remove whitespace from the left side of the 'Country' column.

Pandas
df['Country'] = df['Country'].str.[1]()
Drag options to blanks, or click blank then click option'
Alstrip
Bstrip
Crstrip
Dtrim
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rstrip' which removes whitespace from the right side.
Using 'strip' which removes whitespace from both sides.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 4 characters.

Pandas
lengths = {word: [1] for word in words if len(word) [2] 4}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' which filters shorter words.
Using 'word' instead of 'len(word)' which would store the word itself.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

Pandas
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' which does not change key case.
Using '<' instead of '>' which filters values less than zero.