Skip to main content
Colin Jaffe/2 min read

Analyzing Apple Price Peaks Using Pandas for Data Insights

Data Science Foundations

Statistics

Hypothesis testing, distributions, sampling — the math behind decisions.

Programming

Python or R — pandas, numpy, scikit-learn.

Communication

Explain findings to non-technical stakeholders.

Domain Knowledge

Context separates analysis from insight.

Master Data Science at Noble Desktop

Noble Desktop's Data Science & AI Certificate covers Python, machine learning, and the modern data science stack.

This lesson is a preview from our Data Science & AI Certificate Online (includes software) and Python Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.

Find the highest apple price and corresponding date using pandas, and then plot the data. Watch this tutorial to learn the key concepts and techniques.

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.