LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Working with Categorical Data in Python

Kurs anzeigen

Anleitung zur Übung

  • Create a categorical pandas Series without using pd.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.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Create a categorical Series and specify the categories (let pandas know the order matters!)
medals = pd.____(____)
print(medals)
Code bearbeiten und ausführen