Complete the code to convert the 'color' column to categorical type.
df['color'] = df['color'].[1]()
Using astype('category') converts the column to categorical type.
Complete the code to get the categories of the 'color' column after conversion.
categories = df['color'].[1]
The cat.categories attribute gives the categories of a categorical column.
Fix the error in the code to convert 'size' column to categorical with specified order.
df['size'] = pd.Categorical(df['size'], categories=[1], ordered=True)
The categories must be in the correct logical order: small, medium, large.
Fill both blanks to create a new categorical column 'rating_cat' from 'rating' with categories and order.
df['rating_cat'] = pd.Categorical(df['rating'], categories=[1], ordered=[2])
Categories should be ordered low to high, and ordered=True sets the order.
Fill all three blanks to create a categorical column 'grade_cat' from 'grade' with categories, order, and rename categories.
df['grade_cat'] = pd.Categorical(df['grade'], categories=[1], ordered=[2]) df['grade_cat'] = df['grade_cat'].cat.[3](['Poor', 'Average', 'Good'])
Use set_categories to rename categories after creating an ordered categorical with specified categories.