Recall & Review
beginner
What does converting a column to categorical type in pandas do?
It changes the column to a special type that uses less memory and can speed up operations by storing data as categories instead of raw values.
Click to reveal answer
beginner
How do you convert a pandas DataFrame column named 'color' to categorical?
Use
df['color'] = df['color'].astype('category') to convert the 'color' column to categorical type.Click to reveal answer
beginner
Why might you want to convert a text column with repeated values to categorical?
Because it saves memory and can make filtering and grouping faster, just like organizing similar items into labeled boxes instead of keeping them loose.
Click to reveal answer
intermediate
What is the difference between ordered and unordered categorical data?
Ordered categorical data has a meaningful order (like small < medium < large), while unordered categorical data has no order (like red, blue, green).
Click to reveal answer
intermediate
How can you create an ordered categorical column in pandas?
Use
df['size'] = pd.Categorical(df['size'], categories=['small', 'medium', 'large'], ordered=True) to create an ordered categorical column.Click to reveal answer
What is the main benefit of converting a column to categorical in pandas?
✗ Incorrect
Converting to categorical saves memory and can speed up operations by storing repeated values efficiently.
Which pandas method converts a column to categorical type?
✗ Incorrect
The astype('category') method converts a column to categorical type.
What does ordered=True do when creating a categorical column?
✗ Incorrect
Setting ordered=True defines a meaningful order among categories.
Which of these is NOT a reason to use categorical data?
✗ Incorrect
Categorical data does not automatically fix missing data.
If you have a column with values 'red', 'blue', 'green', what type is best to convert it to?
✗ Incorrect
Categorical type is best for repeated text values like colors.
Explain why and how you would convert a text column with repeated values to categorical in pandas.
Think about how repeated labels can be stored more efficiently.
You got /4 concepts.
Describe the difference between ordered and unordered categorical data and give an example of each.
Consider sizes for ordered and colors for unordered.
You got /4 concepts.