>> As is mentioned on the outset,
what we're going to focus in on is some of
the common libraries and tooling that you're going to
use when it comes to working down the path of data science.
So along those lines,
we're going to take a look at are
really common library known as pandas.
Now sorry to disappoint right upfront,
so this has nothing to do with the bears,
I know I was disappointed when I first found that out.
But rather it's a library that has a couple of
very common utilities that you'll be using to help work with,
manage, and manipulate the data as you start to analyze it.
So what is pandas?
Pandas is an open source BSD-license library,
and it's really geared towards
high performance and familiar data structures,
that what you're going to notice in here
is that we're going to have a serious library
that's going to be a little bit like a list
only gives us a couple of additional tools as well.
We're also going to see a DataFrame where if you've played
around with Excel or maybe a relational database,
that you'll feel very comfortable inside of a DataFrame.
So first up, what is series?
Well, Series is very similar to a Python list,
that what it's going to be is a single dimensional array of
objects where I have all of my values sitting there,
and they'll have some form of an index.
One big difference however,
between a Series and a List is the fact that we
can set our index to really be whatever it is that we might want.
By default, it's going to be zero based,
but if you do need some level of control over that,
you can have that as opposed to
an index which is always going to be in zero based.
Now to create a brand new series,
what you're going to do is use the constructor.
So if you've already played around with classes before,
you'll know that you go ahead and call
this just like you would a normal method,
and then pass in the appropriate items.
You'll notice that when you get right down to it,
what we're doing here is we're really actually just
converting in a list into a series.
So you'll notice the square brackets here,
that's what we're using to indicate a list typically.
So we're actually converting this into a series.
The other thing that I want to highlight here,
is you'll notice this little pd right here.
You might be wondering, "Okay.
Well, what is pd?"
Commonly, when you import in the pandas library,
you'll rename this as pd,
pd being short for pandas.
If you've seen me do other videos,
you may know the fact that I really don't like single, and two,
and three letter variable names or otherwise,
that to me it's not necessarily as clear as to what it might be.
That being said, I will always go with convention.
So convention always override
my own personal opinion because well,
I have opinions on everything.
But the community has decided that when we use
pandas that we'll go ahead and abbreviate this as pd.
So I follow right along with that,
and I do recommend that you do the same,
that whenever there's a convention,
you should go ahead and fall in line there because after all,
it's not just going to be you that we'll be looking at your code,
but it's frequently going to be other Python developers as well,
and you want to make sure that they know what it
is that you've been up to inside of your code.
So while I'm not necessarily
a fan of one and two letter variable and namespace names,
I'll still go ahead and use pd because
again, that's the convention.
So you'll notice here we can go ahead and set all this up.
When we go ahead and display this,
it will then show up as
just simply that little list right there with the index,
and you're also going to notice that if I
want to go access a particular item,
I can use the normal index functions.
So here is my airports with two just like that.
I can do a for loop to loop through each one of those.
So if I print all of those out,
you'll notice that I'll get Seattle-Tacoma,
Dulles, London Heathrow, and Schiphol,
down at the very bottom.
Okay. Let's turn our attention now to DataFrames.
I would say that this is probably
the most common datatype that you'll
be using when you're getting in and
playing around inside of anything that's data science.
A DataFrame is a two dimensional data structure.
If you've played around inside of a database,
if you've played around inside of a spreadsheet,
you're going to feel very much at home here.
Because what you're going to notice is that we have
columns and we have our rows,
and our columns are going to have names.
So you'll notice that we've got name here,
we've got city here,
we've got country, all the way on the end there.
We've got our normal columns,
just like we would expect.
You're also going to notice again
similar or more to a database then
maybe to a spreadsheet that we'll also have
a column that will be our index,
and you'll also notice that you'll have
the ability to control that,
by default it's going to be zero-based.
But if maybe I'm importing in from somewhere else,
maybe from a table,
maybe from a CSV file,
maybe there is already IDs that have been set,
that I could go in and identify, hey,
this is the column that I want you to use as
an index rather than doing the zero-based there.
So you do get the ability to control that.
If you want to create a DataFrame,
what you're going to notice is that we'll use again a constructor,
but effectively we're going to convert
a list of lists into our DataFrame.
So I want to highlight just this item right here,
where you'll notice that we've got Seattle-Tacoma,
which is the name of the airport.
You'll notice that we've got the city, which is Seattle,
and then we've got the country, which is USA.
Then you'll notice the next list down below that,
I'll highlight that one in blue here.
You'll notice on that one that we've got Dulles,
we've got Washington, and USA.
So again, we've got the name of the airport,
the city, and the country.
So each one of those is an individual list.
We're going to take all of those together,
convert that into a DataFrame,
and the result is going to wind up being
that little table that you're seeing right there.
So you'll notice that Seattle-Tacoma,
Dulles, London Heathrow, Schiphol,
and Changi, all become our individual airport names.
Just imagine if you are the Changi was added onto there,
even though it just wasn't listed in the code above.
You'll notice the cities,
and then you'll also notice the countries.
So what happened is we took those lists
and we converted that into a table structure.
But what I want you to notice is the column names there.
The column names are quite frankly,
not overly helpful that I got column names of zero, one, and two.
Zero, one, and two don't tell me anything.
Not only that, but dealing with data where
everything depends on position can get really tricky,
because you have to be really careful about
things moving around and so forth.
So whenever we can identify something based on name,
that's typically going to be the way that we want to do it.
So rather than going with those numbers that we see by default,
let's instead identify what our column names should be.
So you'll notice the last parameter there,
which is our columns.
So now when we run this bit of code,
now we'll actually wind up with the column names.
So you'll notice that we've got name,
we've got city, and we've got country.
You're going to notice that there is a lot of tools
that are available to us inside of the DataFrame,
and we're going to take a look at those
in the next couple of videos.
But for now, this is how we go in and create the items.
Let's get in and take a look at a couple of real quick code demos,
so we can see this in action.