In this video, we'll analyze some data with Pandas.
Okay, I've got Jupyter Notebooks open and I'm going to click
data_analysis_panda.ipynb to open that notebook in a new tab.
And I have all the operations I'm going to perform in this video
in separate cells.
Okay, so first I'm going to import Pandas as pd, then I'm going to read
a local CSV file, that is my mileage or mpg.csv file.
So for that I'm using read_csv, just calling that method.
And now, I'm going to take a look at head for my data frame.
So this is the data for my data frame, I've got MPG, Cyl,
Displacement, Horsepower, Weight, Acceleration, Year, CountryCode, and Model.
If I want to get some insightful information, I can just use the info method.
So the info method tells me that it's a Pandas data frame,
that it has 392 entries, 9 columns.
Okay, now, what is the average weight of each auto?
And for this, I'm just calling the mean method.
So the average weight or mean weight is a little over 2,977 pounds.
Now, how much does the heaviest auto weigh?
And for that I'm calling the max method, and that is 5,140 pounds.
Okay, and now what automobiles have the highest displacement engines?
And for that, what I'm doing is I'm making a conditional selection.
Okay, so that conditional selection is based on the displacement
in the data frame being the maximum displacement.
And that returns the index and that will give me
the automobile or automobiles with the highest displacement engines.
And there is a three-way tie.
So the highest displacement is 455, that is cubic inches.
And these are older vehicles, and they're quite large vehicles.
You can see that their weight is pretty high.
Next, what is the highest mileage automobile?
And in the first instance here, I'm going to just grab the model.
Okay, and that is a mazda glc.
Now, if I wanted all the information for that vehicle,
I would just take off model from the end.
Because that is not the only column I want to see, I want to see all of them.
And that returns all of them.
And you can see the MPG is much higher than the older,
heavier vehicles with the higher displacement that we saw earlier.
The engine is a lot smaller, displacement is smaller, horsepower is way less,
weight is a lot less as well.
Of course, acceleration is not as good.
It's a newer vehicle, country code is 3, and the model is mazda glc.
Okay, let's take a look at average mile per gallon
by year of all vehicles in the data set.
Okay, so let's take a look here.
And this is an interesting trend.
So there seems to be a decided trend towards
more fuel efficient or higher mile per gallon vehicles.
So you can see, especially since 1975, that value seems to be trending up.
But what about average weight or mean weight?
Well, this appears to have a decided trend towards lower weight.
So, so far,
we're seeing a trend towards higher miles per gallon and lower weight.
Now, let's look at displacement of the engines.
And here again, we see a downward trend in the displacement of engines.
So there appears to be, over the years, an emphasis towards
higher fuel efficiency, lower weight, and lower displacement engines.
Okay, so that is data analysis with Pandas.