Complete the code to apply a function that doubles each value in the 'score' column.
df['double_score'] = df['score'].[1](lambda x: x * 2)
The apply() function lets you run a custom function on each element of the column. Here, it doubles each score.
Complete the code to apply a function that returns 'Pass' if score is 50 or more, else 'Fail'.
df['result'] = df['score'].[1](lambda x: 'Pass' if x >= 50 else 'Fail')
Using apply() lets us run a custom function that checks each score and returns 'Pass' or 'Fail'.
Fix the error in applying a function that adds 10 to each value in the 'score' column.
df['new_score'] = df['score'].[1](lambda x: x + 10)
apply() is the correct method to apply a function to each element. map() works differently and filter() is for filtering rows.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
lengths = {word: [1] for word in words if len(word) [2] 3}The dictionary comprehension uses len(word) to get length and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase keys and values only if value is positive.
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}The dictionary comprehension uses k.upper() for keys, v for values, and filters values greater than 0 with >.