Complete the code to add a new column 'total' as the sum of columns 'a' and 'b'.
import pandas as pd df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}) df['total'] = df['a'] [1] df['b'] print(df)
Use the plus sign + to add the two columns element-wise.
Complete the code to create a new column 'is_high' that is True if 'score' is greater than 50.
import pandas as pd df = pd.DataFrame({'score': [45, 60, 30]}) df['is_high'] = df['score'] [1] 50 print(df)
The operator > checks if values are greater than 50.
Fix the error in the code to create a new column 'double' that doubles the values in 'num'.
import pandas as pd df = pd.DataFrame({'num': [1, 2, 3]}) df['double'] = df['num'] [1] 2 print(df)
Use the multiplication operator * to double the values.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2] > 3} print(lengths)
Use len(word) to get the length and filter with len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their scores only if score is above 50.
data = {'apple': 40, 'banana': 60, 'cherry': 70}
result = { [1]: [2] for [3], score in data.items() if score > 50 }
print(result)Use word.upper() as key, score as value, and word as the loop variable.