0
0
Pandasdata~10 mins

Multiple conditions with & and | 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 'age' column is greater than 30.

Pandas
filtered = df[df['age'] [1] 30]
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will select wrong rows.
Using '==' will select only rows where age is exactly 30.
2fill in blank
medium

Complete the code to select rows where 'age' is greater than 30 and 'score' is at least 80.

Pandas
filtered = df[(df['age'] > 30) [1] (df['score'] >= 80)]
Drag options to blanks, or click blank then click option'
A|
B&
Cor
Dand
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'and' or 'or' directly causes errors in pandas.
Using '|' instead of '&' changes the logic to 'or'.
3fill in blank
hard

Fix the error in the code to select rows where 'age' is less than 25 or 'score' is greater than 90.

Pandas
filtered = df[(df['age'] [1] 25) | (df['score'] > 90)]
Drag options to blanks, or click blank then click option'
A<
B<=
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' selects ages 25 and below, which is not the requirement.
Using '>' or '==' will select wrong rows.
4fill in blank
hard

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

Pandas
lengths = {word: [1] for word in words if len(word) [2] 4}
Drag options to blanks, or click blank then click option'
Alen(word)
B<=
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' includes words of length 4 or less.
Using 'word' as value stores the word itself, not its length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their scores for scores above 50.

Pandas
result = { [1]: [2] for word, score in data.items() if score [3] 50 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bscore
C>
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() for keys instead of uppercase.
Using '<' or '<=' in condition selects wrong scores.