Learn how to visualize Apple's historical stock prices using Python's pyplot library, including methods to pinpoint and plot significant highs and lows. Gain practical experience in identifying and marking critical data points on stock price charts.
Key Insights
- The tutorial demonstrates plotting Apple's historical stock prices by using Python's pyplot with the BMH style, visualizing closing prices over time.
- It explains how to identify and retrieve significant data points, such as the lowest stock price, by using pandas functions like
min()
and indexing techniques. - The article introduces an additional challenge to readers, suggesting the use of pyplot's scatterplot method to highlight both the highest and lowest points on the plotted graph.
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 plot some data. First, I am going to want the low, so I'm going to add that here as well. Get rid of the prints, we don't really need those.
Let's add, find the lowest price in the data frame. That'll be lowest apple price equals, and it's going to be very similar, really the reverse. I want the low dot min.
Give me the lowest of the lows, and then let's find the row with that price. Low date is apple prices, and it will be apple prices. Yeah, apple prices at the low column equals our lowest apple price.
And finally, let's actually get the date from that. That'll be low date is actually low date at dot index and index zero. Let's run that block again.
And now, first, now that we're graphing it, let's just see, I don't have quite everything here, but if I run this, it's going to make a big old pyplot figure using the BMH style. And we say go plot the dates as X's against the closing prices as the Y. And then pyplot, show that graph. And here it is.
Here's apple's low, low prices in the early aughts, and then jumping, jumping, jumping. All right, so that's how we can do some good work with this. Now, I want to give you folks an extra challenge.
Use pyplot's scatterplot method to add the high and the low here. You can kind of eyeball the high. It looks like it's this special day here in 2012, but I'm really not quite clear on where that low is.
Probably somewhere in here. I mean, we can look at the date. We can print out the date.
We've got these dates, low date and low price, high price and high date. We want to take those two X and Y points and plot them using pyplot's scatterplot method. That's our next challenge.
And I'll let you folks do that, and we'll talk about how we do it in the next video. Take a moment, see if you can figure it out on your own.