Aan de slagGa gratis aan de slag

Unique values of a column

One of the main strengths of Matplotlib is that it can be automated to adapt to the data that it receives as input. For example, if you receive data that has an unknown number of categories, you can still create a bar plot that has bars for each category.

In this exercise and the next, you will be visualizing the weight of athletes in the 2016 summer Olympic Games again, from a dataset that has some unknown number of branches of sports in it. This will be loaded into memory as a pandas DataFrame object called summer_2016_medals, which has a column called "Sport" that tells you to which branch of sport each row corresponds. There is also a "Weight" column that tells you the weight of each athlete.

In this exercise, we will extract the unique values of the "Sport" column

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with Matplotlib

Cursus bekijken

Oefeninstructies

  • Create a variable called sports_column that holds the data from the "Sport" column of the DataFrame object.
  • Use the unique method of this variable to find all the unique different sports that are present in this data, and assign these values into a new variable called sports.
  • Print the sports variable to the console.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Extract the "Sport" column
sports_column = ____

# Find the unique values of the "Sport" column
sports = ____

# Print out the unique sports values
____
Code bewerken en uitvoeren