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
From the course: Data Analysis with Python and Pandas
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
pandas and NumPy intro2m 53s
-
(Locked)
NumPy arrays and array properties7m 41s
-
(Locked)
Challenge: Array basics1m 47s
-
(Locked)
Solution: Array basics2m 2s
-
(Locked)
Array creation8m 13s
-
(Locked)
Random number generation5m 58s
-
(Locked)
Challenge: Array creation1m 30s
-
(Locked)
Solution: Array creation4m 22s
-
(Locked)
Indexing and slicing arrays9m 9s
-
(Locked)
Challenge: Indexing and slicing arrays1m 6s
-
(Locked)
Solution: Indexing and slicing arrays2m 23s
-
(Locked)
Array operations7m 45s
-
(Locked)
Challenge: Array operations2m 6s
-
(Locked)
Solution: Array operations4m 16s
-
(Locked)
Filtering arrays and modifying array values10m 56s
-
(Locked)
The where() function4m
-
(Locked)
Challenge: Filtering and modifying arrays1m 57s
-
(Locked)
Solution: Filtering and modifying arrays3m 11s
-
(Locked)
Array aggregation6m 51s
-
(Locked)
Array functions7m 41s
-
(Locked)
Sorting arrays3m 51s
-
(Locked)
Challenge: Aggregation and sorting1m 11s
-
(Locked)
Solution: Aggregation and sorting1m 35s
-
(Locked)
Vectorization4m 19s
-
(Locked)
Broadcasting7m 8s
-
(Locked)
Challenge: Bringing it all together2m 45s
-
(Locked)
Solution: Bringing it all together6m 18s
-
(Locked)
Key takeaways1m 56s
-
(Locked)
-
-
-
-
-
-
-
-
-