0
0
Pandasdata~5 mins

Ordered categories in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an ordered category in pandas?
An ordered category is a type of categorical data where the categories have a meaningful order or ranking, like 'low' < 'medium' < 'high'.
Click to reveal answer
beginner
How do you create an ordered categorical column in pandas?
Use pd.Categorical() with the ordered=True parameter and specify the category order with the categories argument.
Click to reveal answer
beginner
Why use ordered categories instead of strings or numbers?
Ordered categories save memory and allow meaningful comparisons like <, >, and sorting based on the order you define.
Click to reveal answer
intermediate
What happens if you compare two ordered categorical values in pandas?
Pandas compares them based on the order you set, not alphabetically or numerically. For example, 'low' < 'high' if 'low' is before 'high' in the category order.
Click to reveal answer
intermediate
How can you change the order of categories in an existing ordered categorical column?
Use the cat.reorder_categories() method with the new order list and ordered=True to update the order.
Click to reveal answer
Which parameter makes a pandas categorical ordered?
Aorder='asc'
Bordered=True
Csort=True
Drank=True
What is the output type when you use pd.Categorical(['low', 'high'], categories=['low', 'medium', 'high'], ordered=True)?
AA pandas Series
BA numpy array
CA list
DAn ordered categorical object
If 'medium' is between 'low' and 'high' in order, what is the result of 'medium' > 'low'?
ATrue
BFalse
CError
DDepends on data type
How do ordered categories help in sorting data?
AThey convert categories to numbers before sorting.
BThey sort data randomly.
CThey allow sorting based on the defined order, not alphabetically.
DThey do not affect sorting.
Which method changes the order of categories in a pandas categorical column?
Acat.reorder_categories()
Bcat.set_order()
Ccat.sort_categories()
Dcat.change_order()
Explain what ordered categories are and why they are useful in pandas.
Think about how you rank things in real life, like sizes or ratings.
You got /4 concepts.
    Describe how to create and modify an ordered categorical column in pandas.
    Focus on the parameters and methods pandas provides.
    You got /4 concepts.