Home > front end >  How to plot correlation between two columns
How to plot correlation between two columns

Time:10-02

The task is the following:

Is there a correlation between the age of an athlete and his result at the Olympics in the entire dataset?

Each athlete has a name, age, medal (gold, silver, bronze or NA).

In my opinion, it is necessary to count the number of all athletes of the same age and calculate the percentage of them who have any kind of medal (data.Medal.notnull()). The graph should show all ages on the x-axis, and the percentage of those who has any medal on the y-axis. How to get this data and create the graphic with help of pandas and matprolib?

For instance, some data like in table:

Name Age Medal
Name1 20 Silver 
Name2 21 NA
Name3 20 NA
Name4 22 Bronze
Name5 22 NA
Name6 21 NA
Name7 20 Gold
Name8 19 Silver
Name9 20 Gold
Name10 20 NA
Name11 21 Silver

The result should be (in the graphic):

19 - 100%
20 - 60%
21 - 33%
22 - 50%

CodePudding user response:

First, turn df.Medal into 1s for a medal and 0s for NaN values using barplot


Incidentally, if you would have wanted to calculate these percentages, one option could have been to use barplot plt

  • Related