‫Welcome back.
‫So the last video we saw plotting a scatterplot or figure out directly from our car sales data frame.
‫We also saw making a line plot and doing a little bit of data manipulation, like adding a date column
‫and creating a total sales column using the come some function.
‫But how about we look at a few different other kinds of plots from our data frames?
‫How about a bar graph?
‫Yeah, that's a good idea.
‫Let's make some data actually, because we want to just keep practicing all these different types of
‫of ways of plotting, creating data and just seeing as many different examples as we can.
‫So we'll create X variable here.
‫We'll go turn it into a data frame.
‫So we want def equals paid a dataframe x columns equals we'll keep it nice and simple.
‫We'll just get a b.
‫C D wonderful.
‫And now we'll have a look at our data frame, nice and simple.
‫So we've got some random values here between zero and one, it looks like, and four columns that are
‫just simple A, B, C, D.
‫Now to get a bar graph, we can do this one way we can do it.
‫Dot plot.
‫Dot bar.
‫This is our DFA here.
‫This is our dataframe.
‫And this is just saying, hey, DFA plot.
‫Make it a bar graph.
‫Let's see what this turns out to be.
‫Wonderful.
‫So this has got a legend here with A, B, C, D, and then we've got the different values for each
‫different row.
‫So this is row zero.
‫We can see a is 0.06.
‫It's fairly low here, but D is 0.95.
‫So it's right up and high.
‫That's a easy way to make a bar graph using a pandas dataframe and a few different columns.
‫How about how about we do it a different way?
‫Let's go.
‫Because again, there's always many different ways to do the same thing with these libraries that we've
‫been looking at.
‫So go do have to plot.
‫Remember how with our scatter graph we had this kind parameter.
‫Well, you can do the same with the bar graph kind it goes bar, put the semicolon at the end we get
‫the exact same plot.
‫These are two different ways that you can hot a bar graph.
‫You can also change the kind variable here.
‫Which one should you use?
‫It's personal preference, but to be honest, I kind of flip back and forth depending on what kind of
‫graph I'm making, but I'm just showing you this.
‫So you've got an idea if you see these two out in the wild somewhere, you know, they're really just
‫doing the same thing.
‫What out next?
‫Let's use our actual data.
‫So that was a dummy plot.
‫Let's use the car sales data frame and make a bar graph.
‫What car sales?
‫Let's view it again.
‫Always good to view your data frames.
‫This is the kind of workflow you'll be going through when you're creating visualizations, as you'll
‫be checking your dataframe, making a visualization, checking your data frame, making a visualization,
‫and just keep jumping back and forth.
‫So never be afraid, especially when you're working through the start of a project to just keep writing
‫code, keep trying to understand your data.
‫So we want car sales dot plot.
‫Maybe we plot the domino versus the make in a bar graph.
‫We can see that maybe the make will be the x, so we'll have make along the bottom and then odometer
‫as the y.
‫So let's see what that turns out to be.
‫Equals X make.
‫And then we want y equals odometer typos.
‫Beautiful.
‫Kind equals bar.
‫There we go.
‫We can see good arrows here across the bottom.
‫We've got different makes Toyota that's how many kilometers are on the odometer.
‫Honda, that's how many kilometers are on this this example.
‫What a bit of an extension might be is to group these together to figure out what the average odometer
‫reading is for each different make.
‫That would be something like consolidating cars of the same make and then averaging what their odometer
‫is.
‫So maybe that's a little bit of a practice that you could try to create an extra column over here or
‫something like that.
‫But let's move on to another type of plot that we've seen before.
‫How about histograms?
‫Histograms are great for visualizing distributions, so that's just the spread of data.
‫So we got of course, there's many different ways to do it.
‫So we got car sales, odometer.
‫We want to visualize the distribution of the odometer plot.
‫Yes, this is just exactly like we saw before with Plot Bar, but now we're doing highest.
‫Here's this shot for histogram.
‫So we'll have a look at this.
‫So that's the spread of our data.
‫This is that kind of that normal distribution curve around this this sort of range, 25000 to 100000.
‫Now, we've got a few here, which are a little bit outside that normal curve here.
‫So this might be considered an outlier because of how high it is.
‫And if we come back to our table, our data frame, we can kind of see that at this Nissan, which is
‫this one here, has 200,000 kilometers on its odometer versus the rest of these are barely scratching
‫towards 100.
‫So that kind of makes sense intuitively just looking at this.
‫But you could imagine if we had maybe a thousand more cars with all different ranges of kilometers,
‫most of them would probably appear in this range if they were similar distribution to what we've got
‫here.
‫Yeah.
‫What's another way of doing it?
‫So if we go car sales, we'll make the same grab here.
‫I don't want to catch em.
‫Beautiful plot.
‫We're going to use the kind parameter here.
‫Kind equals hist and then we'll do it there.
‫So same graph, just a little bit different here.
‫We've used the kind parameter rather than just the dot hist method.
‫So one of the advantages of using the dot hist it has a little parameter here called bins now bins that
‫by default is ten.
‫So this is if you're wondering what a bin is, it's these columns here.
‫What a histogram plot does is it takes the spread of data here.
‫And then buckets them into bins.
‫So we got here.
‫One, two, three, four, five, six, seven, eight, nine.
‫So this is by default ten bins.
‫If your data doesn't fit into ten different evenly sized bins, it might adjust the size here.
‫But we can do that manually by passing a different value to hist to the bins parameter.
‫So let's see that in action.
‫Let's go.
‫Plot hissed.
‫We're going to change bins.
‫Let's do 20.
‫We'll double it up.
‫Okay.
‫So we can say we've kind of missed that curve there.
‫Now, what is the most ideal value for Benz?
‫It's kind of like an exploration.
‫That's a lot of what data science and machine learning is.
‫It's kind of just trying things out and seeing what works.
‫So these don't really look that great.
‫I think ten is actually probably one of the best values.
‫It's probably all right.
‫Well, we do have only ten samples now.
‫What are you looking for here?
‫You're looking for a big curve.
‫Like, remember how we looked at the normal distribution?
‫You want to try and find something like this with your histograms, a curve like this.
‫And if you can't find exact curve because your data doesn't fit this exact curve, that's not a problem.
‫It's just about having a different go and figuring out what is the most ideal number of bins for your
‫histograms.
‫All right.
‫So we've seen a histogram, we've seen bar graph, we've seen scatter plots, we've seen line plots
‫on our car sales data set.
‫Let's try to do something a little bit similar, but with another data set just to make sure that we've
‫kind of got these methods down pat.
‫So in the meantime, have a little bit of a practice, make a bar graph, make a histogram on the car
‫sales data frame and I'll see you back in the next video.
‫We'll do something similar with another data set.