0
0
Data Analysis Pythondata~10 mins

String methods on Series 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 all strings in the Series to lowercase.

Data Analysis Python
import pandas as pd

s = pd.Series(['Apple', 'Banana', 'Cherry'])
lower_s = s.str.[1]()
Drag options to blanks, or click blank then click option'
Aupper
Blower
Ccapitalize
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using str.upper() instead of str.lower()
Forgetting to use the str accessor before the method
2fill in blank
medium

Complete the code to check if each string in the Series contains the letter 'a'.

Data Analysis Python
import pandas as pd

s = pd.Series(['Apple', 'Banana', 'Cherry'])
contains_a = s.str.[1]('a')
Drag options to blanks, or click blank then click option'
Astartswith
Bendswith
Ccontains
Dmatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using str.startswith() or str.endswith() which only check start or end
Using str.match() which expects a regex pattern for full match
3fill in blank
hard

Fix the error in the code to replace all occurrences of 'a' with 'o' in the Series.

Data Analysis Python
import pandas as pd

s = pd.Series(['Apple', 'Banana', 'Cherry'])
replaced = s.str.[1]('a', 'o')
Drag options to blanks, or click blank then click option'
Achange
Bsubstitute
Cswitch
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like str.substitute or str.switch
Forgetting to use the str accessor
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 5 characters.

Data Analysis Python
words = ['apple', 'banana', 'cherry', 'date']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 5
Cword.startswith('b')
Dword == 'apple'
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.startswith('b') which filters by first letter
Using word == 'apple' which filters only one word
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words containing 'e'.

Data Analysis Python
words = ['apple', 'banana', 'cherry', 'date']
result = { [1]: [2] for word in words if word.[3]('e') }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Ccontains
Dstartswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startswith' instead of 'contains' for filtering
Not converting words to uppercase for keys