From the course: pandas Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Final solution

Final solution - pandas Tutorial

From the course: pandas Essential Training

Start my 1-month free trial

Final solution

(swooshing cymbals) - [Instructor] So this is an interesting question that has a lot of moving parts. I'm going to show you one of the ways to solve it. In every Olympics, which US athlete has won the most total number of medals? Include the athlete's discipline. So, again, we're interested in only the athletes from the USA so we use our dataframe and we say, oo.NOC equals USA, and let's store that in the variable, which is our dataframe, gy. Now, given that we want to determine the values for every Olympics, we will need to group by the Edition, the Athlete, the Medal. So, if I do a groupby on the gy dataframe on the Edition, the Athlete, and the Medal, and I do a sizeof there, I can see that I've got the Edition, the Athlete, and the Medals. So, I want to do an unstack, and the reason I want to do an unstack is because, then, I'm in a position to have three different columns, Silver, Gold, and Bronze, and then I can add those three columns to get the total number of medals. So, I do…

Contents