Learn how to efficiently identify and extract maximum values from numeric datasets using pandas. Enhance your data analysis skills by pinpointing specific data points, dates, and generating clear visualizations.
Key Insights
- Use pandas' numeric data handling capabilities to quickly determine the maximum value in a dataset by utilizing methods such as
.max()
to find the highest-priced apple in the dataset. - Apply filtering techniques effectively in pandas to identify and isolate specific rows matching certain conditions, such as retrieving the exact date associated with the maximum apple price.
- Create clear and informative visualizations of your data to effectively present analytical insights and wrap up your analysis using APIs.
Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.
Let's take a look at how we might go about finding a solution for this problem. First, if we want the highest price—well, this is part of why we made the price numeric. It's for problems like this.
We can say, because it's a numeric value, we can say apple_prices
—oh, maybe let's call it highest_apple_price
—equals—there we go—apple_prices["2. high"].max()
. What's the highest value in that column? And because it's a numeric value, we can do this. Now, finding the row containing that price isn't too hard either.
We can do a filter where we say high_date
maybe—apple_prices[apple_prices["2. high"] == highest_apple_price]
. We find the row where this column value equals the highest price. Now, that actually gives us, as it says here, the row containing that price.
We don't actually have a date yet, but we can get that. We just say high_date
—we don’t really need that full row—so I'm going to overwrite it. I'm going to reassign that variable to be row.index[0]
.
Then let's take a look—if we print highest_apple_price
and also print the date for that highest price. I can do this—there we go. The date is high_date
.
All right, highest price—I happen to know this result is correct. The date was 2012. Okay, we were able to do that without too much work, if you're familiar with Pandas.
Next, we'll make a nice graph with it to show that we can work with this data in any way we’d like and wrap it up on APIs.