0
0
Data Analysis Pythondata~10 mins

String accessor (.str) methods in Data Analysis Python - 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 in the DataFrame to lowercase using the string accessor.

Data Analysis Python
df['name_lower'] = df['name'].str.[1]()
Drag options to blanks, or click blank then click option'
Acapitalize
Bupper
Clower
Dtitle
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 the '@' symbol using the string accessor.

Data Analysis Python
df['has_at'] = df['email'].str.[1]('@')
Drag options to blanks, or click blank then click option'
Acontains
Bmatch
Cendswith
Dstartswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startswith' checks only the start of the string.
Using 'endswith' checks only the end of the string.
Using 'match' is for regular expressions and may not work as expected here.
3fill in blank
hard

Fix the error in the code to extract the first 3 characters from the 'code' column using the string accessor.

Data Analysis Python
df['code_start'] = df['code'].str.[1](0, 3)
Drag options to blanks, or click blank then click option'
Asubstr
Bget
Cextract
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'substr' is not a valid pandas string accessor method.
Using 'get' is for getting element by index, not substring.
Using 'extract' is for regex extraction, not simple slicing.
4fill in blank
hard

Fill both blanks to create a new column with the 'city' names trimmed of whitespace and converted to uppercase.

Data Analysis Python
df['city_clean'] = df['city'].str.[1]().str.[2]()
Drag options to blanks, or click blank then click option'
Astrip
Blower
Cupper
Dcapitalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lower' instead of 'upper' changes letters to lowercase.
Using 'capitalize' only changes the first letter.
Not stripping whitespace before changing case.
5fill in blank
hard

Fill all three blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 characters.

Data Analysis Python
lengths = { [1]: [2] for [3] in words if len([3]) > 4 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using 'item' instead of 'word' causes confusion.
Not using len(word) for values.