Challenge - 5 Problems
String Series Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of lowercasing a Series with mixed case strings
What is the output of this code?
import pandas as pd s = pd.Series(['Apple', 'Banana', 'Cherry']) result = s.str.lower() print(result)
Data Analysis Python
import pandas as pd s = pd.Series(['Apple', 'Banana', 'Cherry']) result = s.str.lower() print(result)
Attempts:
2 left
💡 Hint
The str.lower() method converts all characters in each string to lowercase.
✗ Incorrect
The str.lower() method applied to a pandas Series converts every string element to lowercase. So 'Apple' becomes 'apple', 'Banana' becomes 'banana', and 'Cherry' becomes 'cherry'.
❓ data_output
intermediate2:00remaining
Count of strings containing a substring in a Series
Given this Series, what is the output of counting how many strings contain 'an'?
import pandas as pd
s = pd.Series(['banana', 'apple', 'mango', 'orange'])
count = s.str.contains('an').sum()
print(count)Data Analysis Python
import pandas as pd s = pd.Series(['banana', 'apple', 'mango', 'orange']) count = s.str.contains('an').sum() print(count)
Attempts:
2 left
💡 Hint
Check which strings have 'an' inside them.
✗ Incorrect
The strings 'banana', 'mango', and 'orange' contain 'an'. So the count is 3.
🔧 Debug
advanced2:00remaining
Identify the error in using str.replace with regex
What error does this code raise?
import pandas as pd
s = pd.Series(['cat', 'bat', 'rat'])
result = s.str.replace('[ab]', '', regex=False)
print(result)Data Analysis Python
import pandas as pd s = pd.Series(['cat', 'bat', 'rat']) result = s.str.replace('[ab]', '', regex=False) print(result)
Attempts:
2 left
💡 Hint
Check the meaning of regex=False when the pattern looks like a regex.
✗ Incorrect
When regex=False, the pattern is treated as a literal string, so using a regex pattern like '[ab]' causes a TypeError because it cannot interpret the pattern as a literal string.
❓ visualization
advanced2:00remaining
Visualize the count of string lengths in a Series
Which option shows the correct bar plot code to visualize the count of string lengths in this Series?
import pandas as pd import matplotlib.pyplot as plt s = pd.Series(['dog', 'cat', 'elephant', 'fox']) lengths = s.str.len() # Which code below plots counts of each length?
Data Analysis Python
import pandas as pd import matplotlib.pyplot as plt s = pd.Series(['dog', 'cat', 'elephant', 'fox']) lengths = s.str.len()
Attempts:
2 left
💡 Hint
We want counts of each length, not the lengths themselves.
✗ Incorrect
value_counts() counts how many times each length appears. sort_index() orders lengths ascending. plot(kind='bar') makes a bar chart of counts.
🚀 Application
expert3:00remaining
Filter Series for strings starting and ending with vowels
Given this Series, which option correctly filters strings that start and end with a vowel?
import pandas as pd s = pd.Series(['apple', 'banana', 'orange', 'umbrella', 'grape', 'avocado'])
Data Analysis Python
import pandas as pd s = pd.Series(['apple', 'banana', 'orange', 'umbrella', 'grape', 'avocado'])
Attempts:
2 left
💡 Hint
Check how to combine startswith and endswith for multiple letters.
✗ Incorrect
Option C uses str.startswith and str.endswith with tuples of vowels, combined with & to filter strings starting and ending with vowels. str.match expects full match, so regex must have $ at end.