0
0
Pandasdata~10 mins

Selecting rows by condition 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 rows where score is not 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 '=>' which is not a valid Python operator.
Using '>=' selects rows with height greater or equal to 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)
Blen(word) > 3
Cword.startswith('a')
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using a condition unrelated to 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 correctly.