Complete the code to convert the 'color' column to a categorical type.
df['color'] = df['color'].[1]
Using astype('category') converts the column to a categorical type, which saves memory.
Complete the code to check the memory usage of the DataFrame before optimization.
print(df.memory_usage([1]=True))
The deep=True option gives a detailed memory usage including object types.
Fix the error in converting the 'city' column to categorical by filling the blank.
df['city'] = df['city'].[1]('category')
The correct method to convert data types in pandas is astype.
Fill both blanks to create a dictionary of category counts for the 'fruit' column.
counts = df['fruit'].[1]().[2]()
value_counts() counts each category, and to_dict() converts the result to a dictionary.
Fill all three blanks to optimize the 'category' column and check its new memory usage.
df['category'] = df['category'].[1]('category') mem_after = df.memory_usage([2]=[3]).sum()
Convert the column using astype('category') and check memory with deep=True.