Hello everyone and welcome to the panels.
BILTON data visualization lecturer and this lecture we're going to go over Panther's own built in capabilities
that are actually built off of that plot live but they allow you to call data visualizations directly
off a data for.
Let's go ahead and jump to the Jupiter notebook.
All right.
Here I am at the Jupiter notebook server.
A quick note.
You should be opening this Jupiter notebook under my thumb for data visualization.
The panel is built in data folder and the reason for that is there's a couple of c c files here called
def 1 2 and 3.
And you see as V files and we're going to be working with to actually show the capabilities of pandas
built in data visualization the lecture notebook is right here.
This panel panels built in data visualization and then you also have an exercise which will go over
later.
I'm going opening you know a book here.
And go ahead and get started.
All right.
Here I am at this notebook and I'm going to go out and say important PI and P are going to import pandas
as PD and then I'm also going to specify plot lived in line so I can see that data visualizations inside
of the actual notebook and then the CACP files that we're going to upload are the ones I want to say
.
PD read C S V pasand d if one and for DF one I'm also going to specify that the index be the first column
at index 0.
So now if I look at the one I can see that the index is actually a time series and that's going to be
important when we actually visualize that out.
And then for a non-time series index I'm going end and say PD read C S V and then pass and just to take
a look at the two said.
Very similar except this is just read data and it has a sequential index.
All right.
Let me go ahead and just show you a quick example of what you can do with these sort of data frames
in these columns.
Imagine we wanted to get a histogram of all the values in the A column for DF 1.
Well pand those can actually do that.
We can just call the EF 1 and then call just off of this and it will actually automatically start creating
a histogram.
And note that it's actually calling map plot live under the hood and you can begin to add in MAP plot
lib arguments or even see more style arguments like the number of bins you want in this histogram.
OK now something to note is this style actually isn't very good looking.
In my opinion.
So what you can do in order to fix that is if you come up to the top or really anywhere in the notebook
go ahead and say import Seaborn as asinus.
And once that's imported If you start running these cells again it will look like a seaborne plot.
Now look a little nicer.
So that's something I like to do.
You can actually see more in styles and the pantless calls will look like them.
Pandas has several plot types built into it and we're going to do just briefly go and show examples
of how to create these plots.
Pretty much all the plots can be done through a command off of the data frame and you can basically
do this with two methods you can call a data frame itself or call the column after data frame.
Let's go in and just do a column now and you can call plots and then under the argument of plot specified
kind.
And there is a list in your notebook and we're going to go throughout this list and then you specify
the keyword of the kind.
So if I wanted to histogram I could also create it this way.
And then here you can add in histogram arguments such as the number of bins you want.
So that's one method of creating For example a history room off of a data frame column called dot plot
and then call kind.
All right the other way you can call a plot using pandas is instead of specifying kind equals hissed
you can actually call hist directly off of plot so you can say dot plot and then that.
This will also create the plot.
This is the method we're going to be using throughout the rest of this lecture so we can either grab
the entire data frame or the column called dot plot and then call dot whatever the plot type we want
.
Let's go ahead and just go through all the plot types and check them out.
So let's go ahead and work with these two which is the non-time series.
So as an example it just has a normal index and one plot you can do is an area plot so you can go ahead
and specify plot area.
And this is essentially just going to show an area plot and which you can also do is specify Alpha as
an argument here.
If you want some more transparency and say Alfas equal to 0.4 and this shows some transparency here
and this is just showing the area of the values you can essentially just think of this as a normal line
plot except the area underneath it has been filled in with some sort of color.
All right that's an area plot and again very easy to call off the data frame.
Let's go ahead and take a look at Bart plot's so you can say assin you're a data frame the two plots
and then bar and so automatically create a bar plot and what this does is it just takes the index value
basically as a category.
So in this case your index should be categorical.
Our data frame is actually it's small enough so this makes sense if we take a look at the data frame
it only has 0 or 9 so this works.
A typical data frame with a sequential index you probably would want to do this.
But if it's a categorical index then as a category we'll just list the values per each column and you
can actually also create this to be stacked by passing in stacked equals true
and you'll get a plot that looks like this.
Basically the exact same thing except except that stacking the values.
Personally I would actually recommend that ease see more and for these types of plots.
But if you're just doing some very quick analysis this sort of thing is going to work for you just calling
it off a pantless.
Now it's called histogram.
Just to clarify what it looks like again.
So going to call it say the if one a dot plot just we've seen this before.
And here's our histogram.
And you can specify the number of bins you want.
So if you want a larger number of bins in order to get a little more clarity as far as Panthers plots
go and doing stuff that's built into Panda's histograms are probably the one to use the most.
You can also do line plots which is another common one that I like to use for Pandurs.
For example if we check out the EF 1 remember that our time series index.
Let's imagine that we wanted to plot the data of one of these time series.
You can go ahead and just say DF one plot and then call line.
This is just going to create a line plot.
And for the line plot you have to specify the X and the Y.
So in this case I want the X to be my actual index so I can say if one index and I want my y to be one
of these columns and you pass in the column as a string.
So I want to go underspecified.
Let's say B.
And if I just run this I get a plot that looks something like this.
Generally just a line plot.
So you can imagine if this was stock information and you wanted to plot it out versus time you can get
something that looks like this.
And so this is all built off of that plot lib.
You can begin adding that plot lib arguments such as the size you want.
So to want something much wider.
You can do something like this.
Or let's say I want to adjust the line with.
Well you can just do LW just like we saw for about Plaut live.
It's the line with to something a little skinnier you can add in markers.
All these other map plotless commands.
So everything you learn about that plot live can be applicable to these data frame plots.
Now let's go ahead and check out scatterplot.
So let's say I have DF one I can say plot that scatter and you're going to have to specify an x and
y.
So for this let's just go ahead and pass and strings of column names.
So a and b and this will create a nice looking scatterplot for us.
Something else you can do is actually set the color based off in another column.
So for instance you can say see the color is going to be equal off column C.
So if I just read that it gets me a black and white.
So if I take a look at the if one just clarify what we're doing here.
Data from when we have a value for a and b and we have a value for c..
So essentially we're showing now three levels of information a three dimensional plot if you will.
Since we have a versus B and then a third argument see displayed by color and you can actually pasan
see map as an argument then passing your own color map.
So for instance cool warm which you've seen before and now you're showing three levels of information
a versus B where they stand and then the color value for c..
Sometimes people don't like to show things by color but prefer to show them by size.
You can actually do that as well instead of passing C as an argument.
Here you'll just go ahead and pass.
S and for s You'll go ahead and in a data frame column.
So for this you have to actually pass in the data frame column itself and you probably if you just do
this the points will be too small.
And then what you can do is multiply this by some sort of factor.
So you can see the points are a versus B and the size indicates how much larger or C value was relative
to each other.
All right.
This is the kind of thing where you probably wouldn't remember this off the top of your head you would
go back to Jupiter notebook book that I have assembled for you and use that as a reference or check
out the documentation.
Let's go ahead and move on to box plots again.
I really like seaborne for box plots but if you just want a quick analysis of a box plot pandas can
do that for you as well.
So you just pass on your whole data frame call plot call box and here you can see a box plot that's
basically automatically done for you per column.
So it just takes every column as a category and then plots the distributions for you as a box plot.
All right.
For by various data you can do a hexagonal plot which you'd actually seen before with Pandurs excuse
me it was Seaborn.
But let me go and make a new data frame for this to actually show up correctly.
So I want to say PD data frame.
I'm going to pass in some random data ran then and I'm going to have this be 1000 by let's say two and
then I'm going to pass and the columns to be just a and b.
And if we take a look at our data frame look something like this.
Just some random data.
A freebie.
I just wanted some more random points here and what I can do since this is by variant are two variables
here.
And B I can say plot Hexton pass and x is equal to a mass and Y is equal to B.
And if you just do this you will get a hex plot.
Now this is essentially like a scatterplot except it's the hexagonal bins.
Right now the bin size is really quite small.
So to change that you can say grid size is equal to 25.
And this will enlarge the size of the hexagons and essentially the hexagons get darker as there's more
points inside of them and you can also change the color mapping here and say See map is equal to something
else.
For instance if we wanted cool warm to be our color mapping you could do that as well.
And then finally we can do kernel density estimation plots.
So if for some reason you don't just want a histogram but you want kernel density estimation you can
call your data frame or a column off your data frame and then cissé plot Haidee.
It will create this kernel density estimation plot for you and you can do the same thing with density
which is another call you can make.
So in say density and that will be the same thing.
So if you want a density or kernel density estimation plot those will be the same thing and you can
actually do this off the entire data frame as well.
You don't have to do it just off of one column if you want to compare the density kernel density estimation
plot of all the columns in your data frame.
All right.
That's it.
Hopefully you can see why this method of plotting directly off of Pandurs is a lot easier than calling
full map plot lib and it balances ease of use with control over the figure.
You should note though if you really want to start customizing your figure you should be falling back
to Seaborn or map plot lib.
These sort of commands are really just for a quick analysis of your data and you probably just go to
the note book quickly reference the kind of plot you want to create and then call it off the data frame
or call it off the column or the data frame.
As far as how we're going to use this throughout the course really the only times we're probably going
to use this is just with a line plot or a histogram to call it very quickly.
For more advanced this Haskel plotters box plots or bar plots I would really recommend going with Seaborn
.
All right I hope you found this useful and I will see you at the next lecture or we're going to describe
the quick exercise for you to practice what we just learned here.
Thanks everyone and I'll see you at the next lecture