0
0
Pandasdata~10 mins

str accessor for string methods 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 convert the 'name' column to lowercase using pandas str accessor.

Pandas
df['name_lower'] = df['name'].str.[1]()
Drag options to blanks, or click blank then click option'
Aupper
Btitle
Ccapitalize
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upper' instead of 'lower' changes letters to uppercase.
Using 'capitalize' only changes the first letter to uppercase.
Using 'title' capitalizes the first letter of each word.
2fill in blank
medium

Complete the code to check if the 'email' column contains '@' using pandas str accessor.

Pandas
df['has_at'] = 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' checks only the beginning of the string.
Using 'endswith' checks only the end of the string.
Using 'match' is for regex matching, not simple substring check.
3fill in blank
hard

Fix the error in the code to remove whitespace from the 'city' column using pandas str accessor.

Pandas
df['city_clean'] = df['city'].str.[1]()
Drag options to blanks, or click blank then click option'
Astrip
Btrim
Cclean
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'trim' is not a pandas str method.
Using 'clean' or 'remove' are not valid string methods.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, only 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 '<' selects words shorter than 4.
Using 'word' as value stores the word itself, not its length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys, values from data, only if value is positive.

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()' keeps keys lowercase.
Using '<' or other operators changes the filter condition incorrectly.