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
This exercise is part of the course
Introduction to Data Visualization with Matplotlib
Exercise instructions
- Create a variable called
sports_column
that holds the data from the"Sport"
column of theDataFrame
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 calledsports
. - Print the
sports
variable to the console.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract the "Sport" column
sports_column = ____
# Find the unique values of the "Sport" column
sports = ____
# Print out the unique sports values
____