0
0
Pandasdata~10 mins

Why string operations matter in Pandas - Test Your Understanding

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

Complete the code to convert the 'name' column to lowercase.

Pandas
df['name'] = df['name'].[1]()
Drag options to blanks, or click blank then click option'
Aupper
Blower
Ccapitalize
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upper()' which makes letters uppercase instead.
Using 'capitalize()' which only changes the first letter.
2fill in blank
medium

Complete the code to check if the 'email' column contains '@' symbol.

Pandas
df['email'].str.[1]('@')
Drag options to blanks, or click blank then click option'
Astartswith
Bendswith
Ccontains
Dmatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startswith()' which only checks the beginning of the string.
Using 'endswith()' which only checks the end of the string.
3fill in blank
hard

Fix the error in the code to replace spaces with underscores in the 'city' column.

Pandas
df['city'] = df['city'].str.[1](' ', '_')
Drag options to blanks, or click blank then click option'
Areplace
Bswap
Cchange
Dsubstitute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'swap' which is not a pandas string method.
Using 'change' or 'substitute' which do not exist as string methods.
4fill in blank
hard

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

Pandas
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 4
Cword.startswith('a')
Dword.isupper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using conditions unrelated to length like 'startswith' or 'isupper'.
Using the word itself instead of its length in the dictionary.
5fill in blank
hard

Fill all three blanks to filter a DataFrame for rows where 'name' starts with 'J' and create a list of uppercase names.

Pandas
filtered = df[df['name'].str.[1]('J')]
names = [n.[2]() for n in filtered['name'] if n.[3]()]
Drag options to blanks, or click blank then click option'
Astartswith
Bupper
Cisalpha
Dendswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'endswith' instead of 'startswith' for filtering.
Using 'lower' instead of 'upper' for conversion.
Using 'isdigit' or other checks instead of 'isalpha'.