0
0
Data Analysis Pythondata~10 mins

Why text data requires special handling in Data Analysis Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert a text column to lowercase.

Data Analysis Python
df['text'] = df['text'].[1]()
Drag options to blanks, or click blank then click option'
Alower
Bupper
Cstrip
Dsplit
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper() changes text to uppercase, which is not standard for normalization.
Using strip() removes spaces but does not change case.
Using split() breaks text into words, not case conversion.
2fill in blank
medium

Complete the code to remove punctuation from a text string using Python's string module.

Data Analysis Python
import string
text = 'Hello, world!'
clean_text = ''.join(char for char in text if char not in [1])
Drag options to blanks, or click blank then click option'
Astring.ascii_letters
Bstring.digits
Cstring.punctuation
Dstring.whitespace
Attempts:
3 left
💡 Hint
Common Mistakes
Using string.whitespace removes spaces, which are needed to separate words.
Using string.ascii_letters removes letters, which we want to keep.
Using string.digits removes numbers, which may or may not be desired.
3fill in blank
hard

Fix the error in the code to split text into words correctly.

Data Analysis Python
text = 'Data science is fun'
words = text.[1](' ')
Drag options to blanks, or click blank then click option'
Asplit
Bjoin
Creplace
Dstrip
Attempts:
3 left
💡 Hint
Common Mistakes
Using join() combines a list into a string, not splitting.
Using replace() changes characters but does not split.
Using strip() removes spaces at ends but does not split.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Data Analysis Python
words = ['data', 'is', 'fun', 'science']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) gives the word itself, not its length.
Using '<=' includes short words, not filtering correctly.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words with length greater than 2.

Data Analysis Python
words = ['cat', 'is', 'big', 'dog']
result = [1] for word in words if len(word) [2] 2]
result = {w.[3](): w for w in result}
Drag options to blanks, or click blank then click option'
A[word.upper()
B>
Cupper
Dword.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word.upper()' in the first blank is incorrect syntax for list comprehension start.
Using '<' instead of '>' filters wrong words.
Using 'upper()' with parentheses in dictionary key causes error; method name only is needed.