Creating a categorical pandas Series
Another colleague at work has collected information on the number of "Gold"
, "Silver"
, and "Bronze"
medals won by the USA at the Summer & Winter Olympics since 1896. She has provided this as a list, medals_won
. Before taking a look at the total number of each medal won, you want to create a categorical pandas
Series. However, you know that these medals have a specific order to them and that Gold is better than Silver, but Silver is better than Bronze. Use the object, medals_won
, to help.
This exercise is part of the course
Working with Categorical Data in Python
Exercise instructions
- Create a categorical
pandas
Series without usingpd.Series()
. - Specify the three known medal categories such that
"Bronze"
<"Silver"
<"Gold"
. - Specify that the order of the categories is important when creating this Series.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a categorical Series and specify the categories (let pandas know the order matters!)
medals = pd.____(____)
print(medals)