From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Solution: Aggregation and sorting

Solution: Aggregation and sorting

- [Instructor] All right, everybody. Our solution code is up on the right. Let's go ahead and dive into the notebook. All right, so the trickiest part of this was probably getting those top three prices. And the trick here was to sort prices. Using the sort method, we'll sort prices in place. And now if I grab prices, and if I were just to slice the last three elements of prices, these are going to be our three highest prices, right? We sorted prices from lowest to highest, and so if we just grab the last three elements, those are going to be the highest three prices. Once we have that, it's just going to be a matter of applying our aggregation methods. So top three mean is going to be the mean of this top three array. So let's go ahead and create that here. So top three is going to be equal to the last three elements of our sorted array. And then we just need to call our mean, min, max methods on top three, and then pass top three into our median function to get our key statistics…

Contents