0
0
Pandasdata~10 mins

isin() for value matching 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 'color' column values are in the list ['red', 'blue'].

Pandas
filtered = df[df['color'].[1](['red', 'blue'])]
Drag options to blanks, or click blank then click option'
Acontains
Bmatch
Cisin
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is for string matching, not list membership.
Using 'equals' which compares exact values, not membership.
2fill in blank
medium

Complete the code to filter rows where the 'age' column values are in the list [25, 30, 35].

Pandas
result = data[data['age'].[1]([25, 30, 35])]
Drag options to blanks, or click blank then click option'
Aisin
Bcontains
Cin_list
Dmatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is for substring checks.
Using 'in_list' which is not a pandas method.
3fill in blank
hard

Fix the error in the code to correctly filter rows where 'status' is either 'active' or 'pending'.

Pandas
filtered_data = df[df['status'].[1](['active', 'pending'])]
Drag options to blanks, or click blank then click option'
Aisin
Bmatch
Ccontains
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equals' which only compares single values.
Using 'contains' which is for string matching.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

Pandas
{word: [1] for word in words if [2]
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.
Checking if the word is greater than 3 instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if the length is greater than 4.

Pandas
{ [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 4
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase words as keys instead of uppercase.
Using the word itself as value instead of its length.
Filtering by word length less than or equal to 4.