0
0
Pandasdata~10 mins

Why vectorized operations matter in Pandas - Test Your Understanding

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

Complete the code to create a new column 'double' by doubling the 'value' column using vectorized operation.

Pandas
df['double'] = df['value'] [1] 2
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds 2 instead of doubling.
Using '-' or '/' changes values incorrectly.
2fill in blank
medium

Complete the code to calculate the mean of the 'score' column using a vectorized pandas method.

Pandas
mean_score = df['score'].[1]()
Drag options to blanks, or click blank then click option'
Asum
Bcount
Cmax
Dmean
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() returns total, not average.
Using count() returns number of entries.
3fill in blank
hard

Fix the error in the code to filter rows where 'age' is greater than 30 using vectorized comparison.

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 '==' selects only age exactly 30.
Using '<=' selects ages 30 or less.
4fill in blank
hard

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

Pandas
{word: [1] for word in words if [2] > 3}
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'len(word)' returns the word itself, not length.
Checking 'word > 3' causes error because word is string.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if value is positive.

Pandas
result = [1]: [2] for [3], [2] in data.items() if [2] > 0}}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'v' causes undefined variable error.
Using 'value' as loop variable is inconsistent.
Not using k.upper() returns keys in original case.