Complete the code to convert the 'age' column to a smaller integer type.
df['age'] = df['age'].astype([1])
Using int8 reduces memory usage by storing integers in 8 bits, suitable for small integer ranges like age.
Complete the code to convert the 'category' column to a categorical data type.
df['category'] = df['category'].[1]('category')
to_numeric which converts to numbers, not categories.astype('category') as a method without arguments.The astype method is used to convert data types. You need to pass the type as a string argument.
Fix the error in the code to convert the 'score' column to float32.
df['score'] = df['score'].astype([1])
float which defaults to 64-bit float.The astype method requires the data type as a string, so use "float32" to specify 32-bit float.
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}< which filters shorter words.word instead of len(word) for the value.The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase keys and values greater than zero.
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}k instead of k.upper() for keys.< instead of > in the condition.The dictionary comprehension uses k.upper() to make keys uppercase, keeps values as v, and filters values greater than zero with >.