0
0
Pandasdata~10 mins

Boolean indexing 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[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 rows with age less than 30.
Using '==' will select rows where age is exactly 30.
2fill in blank
medium

Complete the code to select rows where the 'score' column is equal to 100.

Pandas
perfect_scores = df[df['score'] [1] 100]
Drag options to blanks, or click blank then click option'
A==
B>=
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' causes syntax errors.
Using '>=' selects scores greater than or equal to 100, not just 100.
3fill in blank
hard

Fix the error in the code to select rows where 'height' is less than 170.

Pandas
short_people = df[df['height'] [1] 170]
Drag options to blanks, or click blank then click option'
A>
B=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '<' causes syntax errors.
Using '==' selects rows where height equals 170, not less than 170.
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
lengths = {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.
Using the word in the condition instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their scores only if the score is greater than 50.

Pandas
result = [1]: [2] for word, score in data.items() if [3]
Drag options to blanks, or click blank then click option'
Aword.upper()
Bscore
Cscore > 50
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase words as keys instead of uppercase.
Not filtering scores greater than 50.