Analyzing Apple Price Peaks Using Pandas for Data Insights

Find the highest apple price and corresponding date using pandas, and then plot the data.

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.

Python for Data Science Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

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.

Colin Jaffe

Colin Jaffe is a programmer, writer, and teacher with a passion for creative code, customizable computing environments, and simple puns. He loves teaching code, from the fundamentals of algorithmic thinking to the business logic and user flow of application building—he particularly enjoys teaching JavaScript, Python, API design, and front-end frameworks.

Colin has taught code to a diverse group of students since learning to code himself, including young men of color at All-Star Code, elementary school kids at The Coding Space, and marginalized groups at Pursuit. He also works as an instructor for Noble Desktop, where he teaches classes in the Full-Stack Web Development Certificate and the Data Science & AI Certificate.

Colin lives in Brooklyn with his wife, two kids, and many intricate board games.

More articles by Colin Jaffe

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram