0
0
Pandasdata~10 mins

Vectorized operations vs loops in Pandas - Interactive Practice

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 operations.

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 '+' instead of '*' will add 2 to each value, not double it.
Using '/' will divide values, not double them.
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'
Amean
Bsum
Ccount
Dmedian
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() returns total, not average.
Using count() returns number of entries, not average.
3fill in blank
hard

Fix the error in the loop that adds 10 to each element in the 'points' column and stores results in a list.

Pandas
results = []
for [1] in df['points']:
    results.append(x + 10)
Drag options to blanks, or click blank then click option'
Ai
Bx
Cpoint
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name in the loop and inside the loop body causes a NameError.
Using 'i' or 'point' without updating the append statement.
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 len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using '<' instead of '>' in the condition.
5fill in blank
hard

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

Pandas
result = { [1]: [2] for word, score in data.items() if score [3] 0 }
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() instead of uppercase.
Using '<' instead of '>' in the condition.
Mapping keys or values incorrectly.