0
0
Pandasdata~10 mins

Regex operations in Pandas - Interactive Code Practice

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

Complete the code to select rows where the 'Name' column contains the letter 'a'.

Pandas
filtered = df[df['Name'].str.[1]('a')]
Drag options to blanks, or click blank then click option'
Areplace
Bmatch
Cfindall
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'match' instead of 'contains' which only checks the start of the string.
Using 'replace' which changes strings instead of filtering.
2fill in blank
medium

Complete the code to replace all digits in the 'Code' column with '#' symbol.

Pandas
df['Code'] = df['Code'].str.[1]('\d', '#')
Drag options to blanks, or click blank then click option'
Areplace
Bcontains
Cmatch
Dfindall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which only checks for presence but does not replace.
Using 'match' which only checks the start of the string.
3fill in blank
hard

Fix the error in the code to find all words starting with 'a' in the 'Text' column.

Pandas
df['Words'] = df['Text'].str.[1]('\ba\w*')
Drag options to blanks, or click blank then click option'
Afindall
Breplace
Ccontains
Dmatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'match' which only checks the start of the string and returns a boolean.
Using 'contains' which returns a boolean, not the matched words.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, only 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'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<' instead of '>' which selects shorter words.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys, their counts as values, only for counts greater than 1.

Pandas
result = [1]: [2] for word, count in counts.items() if count [3] 1}
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcount
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word instead of uppercase for keys.
Using '<' instead of '>' which filters wrong counts.