Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using str.upper() instead of str.lower()
Forgetting to use the str accessor before the method
✗ Incorrect
The str.lower() method converts all characters in each string of the Series to lowercase.
2fill in blank
mediumComplete 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'
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
✗ Incorrect
The str.contains() method checks if each string contains the specified substring.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like str.substitute or str.switch
Forgetting to use the str accessor
✗ Incorrect
The correct method to replace substrings in Series strings is str.replace().
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.startswith('b') which filters by first letter
Using word == 'apple' which filters only one word
✗ Incorrect
The dictionary comprehension uses len(word) as value and filters words with length greater than 5.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startswith' instead of 'contains' for filtering
Not converting words to uppercase for keys
✗ Incorrect
The dictionary comprehension uses word.upper() as key, len(word) as value, and filters words containing 'e' using str.contains.