Complete the code to create a new column 'age_squared' by squaring the 'age' column.
df['age_squared'] = df['age'] [1] 2
We use the ** operator to raise numbers to a power in pandas.
Complete the code to create a new column 'is_adult' that is True if 'age' is 18 or more, else False.
df['is_adult'] = df['age'] [1] 18
The operator >= checks if age is greater than or equal to 18.
Fix the error in the code to create a new column 'bmi' as weight divided by height squared.
df['bmi'] = df['weight'] / (df['height'] [1] 2)
To square height, we use the power operator **.
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}We want the length of each word as the value, so use len(word). We only want words longer than 3, so use >.
Fill all three blanks to create a dictionary with uppercase keys and values only for items with positive values.
result = [1]: [2] for k, v in data.items() if v [3] 0
Keys are converted to uppercase with k.upper(). Values are v. We filter for values greater than zero using >.