Complete the code to create a simple function that doubles a number.
def double(x): return x [1] 2 result = double(5) print(result)
The function multiplies the input by 2 to double it.
Complete the code to apply a custom function to a pandas DataFrame column.
import pandas as pd def add_five(n): return n + 5 df = pd.DataFrame({'num': [1, 2, 3]}) df['new_num'] = df['num'].[1](add_five) print(df)
applymap which works on DataFrames, not Series.The apply method applies a function to each element in the Series.
Fix the error in the custom function that should return the square of a number.
def square(x): return x [1] x print(square(4))
To get the square, multiply the number by itself using '*'.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'car', 'door'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary maps each word to its length if the length is greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 3.
words = ['apple', 'bat', 'car', 'door'] result = { [1]: [2] for word in words if len(word) [3] 3 } print(result)
word.lower() instead of uppercase.The dictionary comprehension maps each word in uppercase to its length if the length is greater than 3.