Legacy – Multiple Box Chart Workout
- 02:29
Workout demonstrating how to create Multiple Box charts in Python.
Glossary
Matplotlib Multiple Box ChartTranscript
Now we'll look at how to make multiple box charts in a single plot. So this may be to compare different block box plots for different data. So again, we shall be using the s&p 500 companies data that we use for pandas. Before doing anything, we need to import the libraries, import pandas as pd and import matplotlib Pyplot as plt. Now we need to load the dataset data equals pd . read CSV, it's s&p 100 companies. And we'll see as we run this perfect no errors returned. Now in order to do multiple box plots, we need to take a different route, what we need to do is first convert the data into a data frame and then access the separate points. So we take the separate data points from this data set and take it as a dictionary and then convert the dictionary as a data frame. So it's going to be clear once we see how this happens. So we say pd . data frame. And in order to create a dictionary we need curly brackets. And in quotation marks let's say we are taking day one and day five into consideration for the blocks plots. So day one is data.
Day one. And now day five is data . day five and we want a box plot for this so we say dot box plot. And we run this hopefully no errors should be returned. Perfect. Now the only thing left to do is plt . show. And we run this perfect so we can compare the change in the stock prices for the s&p companies all from day one to day five. And this is the same case for any other day we can just keep on adding the values into the dictionary