0
0
Pandasdata~10 mins

apply() with lambda functions 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 apply a lambda function that doubles each value in the 'score' column.

Pandas
df['double_score'] = df['score'].[1](lambda x: x * 2)
Drag options to blanks, or click blank then click option'
Afilter
Bmap
Capply
Dreduce
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of apply, which works differently on Series.
Using filter or reduce, which are not pandas Series methods.
2fill in blank
medium

Complete the code to create a new column 'passed' that is True if 'score' is 50 or more, else False.

Pandas
df['passed'] = df['score'].apply(lambda x: x [1] 50)
Drag options to blanks, or click blank then click option'
A>=
B<=
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' which would mark scores less than or equal to 50 as passing.
Using '==' which only marks scores exactly 50 as passing.
3fill in blank
hard

Fix the error in the lambda function to correctly add 10 to each value in 'score'.

Pandas
df['score_plus_10'] = df['score'].apply(lambda x: x [1] 10)
Drag options to blanks, or click blank then click option'
A-
B/
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which subtracts instead of adding.
Using '*' or '/' which multiply or divide.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Pandas
lengths = {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 '<' instead of '>' which selects shorter words.
Using 'word' as the value instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

Pandas
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of k.upper() for keys.
Using '<' instead of '>' in the condition.