Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the 'Name' column by spaces.
Pandas
df['Name_split'] = df['Name'].str.[1](' ')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join' instead of 'split'.
Forgetting to specify the separator.
Using 'replace' which changes text but does not split.
✗ Incorrect
The str.split() method splits strings in a Series by the specified separator.
2fill in blank
mediumComplete the code to split the 'Address' column by commas.
Pandas
df['Address_parts'] = df['Address'].str.[1](',')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replace' which changes commas but does not split.
Using 'find' which only locates text but does not split.
✗ Incorrect
To split text by commas, use str.split(',').
3fill in blank
hardFix the error in splitting the 'Data' column by semicolon.
Pandas
df['Data_split'] = df['Data'].str.[1](';')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join' which causes an error here.
Using 'replace' which does not split.
✗ Incorrect
The correct method to split strings is str.split(), not join or others.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 letters.
Pandas
lengths = {word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using 'word' instead of 'len(word)' for the value.
✗ Incorrect
The dictionary comprehension maps each word to its length if the word length is greater than 3.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values greater than 0.
Pandas
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' for keys.
Using '<' instead of '>' in the condition.
✗ Incorrect
This dictionary comprehension uses uppercase keys, keeps values, and filters values greater than zero.