- In this and the next couple of videos we're
going to use pandas to read in a popular data
set that's often used by people learning about
data science. And work with that data set in the
context of pandas to explore that data.
Now, on the screen at the moment
I have a URL for a popular data set
repository called R Data Sets.
This repository has over 1100 comma separated
value data sets that you can play with , and one
of them is the titanic disaster data set which
has information about just over 1300 passengers
who were on the ship, and what their fate was
when the ship sank. Now I wanted to show you this
just so you have a sense of the fact that there
are these kind of massive repositories out there
in which you can find data to work with and
learn from as you get into data science
and machine learning and deep learning. The
particular data set we'll be working with like
I said has just over 1300 records , as you can
see some of these have many fewer records.
Some of them have many more records , but these
are just 1 data set repository of the many
that are out there from which you can obtain data
to work with for your own studies and for
learning purposes as well.
I just want to show you that if I search on this
page for titanic, you'll see that the first hit
is the titanic survival data set and what I did
to use this with pandas is I right clicked on
the CSV link over here and copied the URL so that
I can load the data set directly into pandas.
With that said let's switch over to a terminal
window here , you can see I've already imported
pandas.
What we're going to do next is load up
that data set into a pandas data frame.
Because the URL was long I broke it into
two pieces here and concatenated the strings,
but you can see we're using that
same read CSV function that we demonstrated
in the proceeding video to load from a URL this
time instead of from a local file on disk.
So let's go ahead and read that in.
I'm also going to set a setting within pandas
to enable me to display floating point numbers
with two digits to the right of the decimal point
and that will enable me to compact the output
in this example a little bit .
Set option is a function in the pandas library
when you pass it the string precision
that indicates that your setting for all floating
point numbers that are manipulated with pandas
their display precision to be 2.
And that's for onscreen formatting purposes.
I'll go ahead and set that as well.
One of the great thing's about pandas is that
it makes it really easy to explore your data,
which is a key thing you need to do.
You need to get to know your data before you can
work with that data.
For example I can go ahead and type titanic.head
it will give me just the first few rows
of the titanic data set to look at.
The indices are just the indices that
are provided automatically by pandas
starting from index number 0 for the first row.
We have several columns of information here.
This one is not named very well, but it's
the column that specifies passenger names.
We have a column called survived which indicates
weather they survived the disaster or not.
We have a sex column which indicates weather
they were male or female, a age column for
their age at the time of the disaster, and a
passenger class column that indicates which class
they were traveling on the ship.
Now just like you can look at the first few, you
also have the ability to look at the last few
with the tail method .
So these are the last 5 records of the data set
and all these folks were 3rd class passengers.
By the way notice NaN here in record number 305
that person they didn't have a age for, so
that's a missing piece of data in this particular
data set.
At this point we've now displayed just a few of
the records so we can get a sense
of what information is there. Let's also make
a change. These column names are not as perhaps
as readable as they could be, it would be nice if
this one was simply called name and here this
one's really wide and we have pretty narrow data,
so let's also rename that one as well.
To do that I'm going to set the data frames
columns attribute and I have 5 columns here
and I'm going to set all of those column names.
For a few of them we're using the same names they
had previously. But the first column will now be
called name, the last column will now
be called class. After doing that if I go ahead
and display the head of the data's frame once
again you can see we now have our
customized column heads being displayed
across the top of the data frame.
So at this point we've loaded the data frame,
we've started to get to know the data
in the next video we're going to do a little bit
of simple data analysis with the data set.