Ordered categories
📖 Scenario: You work in a store that sells clothes. You have a list of T-shirt sizes from customers. The sizes are small, medium, and large. You want to organize these sizes in order so you can analyze them better.
🎯 Goal: Create a pandas Series with T-shirt sizes as an ordered category. Then, sort the sizes in the correct order: small, medium, large.
📋 What You'll Learn
Create a pandas Series called
sizes with the values: 'medium', 'small', 'large', 'medium', 'small'.Create an ordered categorical type called
size_order with categories: 'small', 'medium', 'large' in this order.Convert the
sizes Series to use the ordered categorical type size_order.Sort the
sizes Series by the ordered categories.Print the sorted
sizes Series.💡 Why This Matters
🌍 Real World
Stores often have product sizes or ratings that have a natural order. Using ordered categories helps sort and analyze such data correctly.
💼 Career
Data analysts and scientists use ordered categories to prepare and clean data for reports and machine learning models.
Progress0 / 4 steps