0
0
Data Analysis Pythondata~10 mins

Text cleaning pipeline 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 text in the list to lowercase.

Data Analysis Python
texts = ['Hello World', 'Data Science']
lower_texts = [text.[1]() for text in texts]
print(lower_texts)
Drag options to blanks, or click blank then click option'
Aupper
Blower
Ctitle
Dcapitalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upper()' instead of 'lower()' changes text to uppercase.
Using 'capitalize()' only changes the first letter.
2fill in blank
medium

Complete the code to remove leading and trailing spaces from each string.

Data Analysis Python
texts = ['  data ', ' science  ']
clean_texts = [text.[1]() for text in texts]
print(clean_texts)
Drag options to blanks, or click blank then click option'
Ajoin
Bsplit
Creplace
Dstrip
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'split()' splits the string into words, not removing spaces.
Using 'replace()' needs extra arguments to remove spaces.
3fill in blank
hard

Fix the error in the code to remove punctuation from the text using string.punctuation.

Data Analysis Python
import string
text = 'Hello, world!'
clean_text = ''.join(char for char in text if char not in [1])
print(clean_text)
Drag options to blanks, or click blank then click option'
Astring.punct
Bstring.punctuations
Cstring.punctuation
Dpunctuation.string
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string.punct' which does not exist.
Swapping the order like 'punctuation.string' which is invalid.
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 [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Comparing the word string directly to a number.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.

Data Analysis Python
words = ['hello', 'data', 'science', 'fun']
result = { [1]: [2] for w in words if [3] }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
Clen(w) > 4
Dw.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Not filtering words by length.