Now we've got a little bit of an overview of what pandas is.
Let's start to code in so to begin we're going to load up a terminal or command prompt.
Now this is a workflow we've been through a couple of times now but we're going to keep going through
with each new concept to make sure we kind of get it down pat because that's what we're good doing right.
We're just practicing and practicing and practicing.
So if we try to access Jupiter notebooks which is our workspace where we want to use pandas we run this
code elsewhere in the base environment.
It's not going to work.
So we need to activate the environment that we've created.
So if I go Conda and list this will show me my environments and in my case I want to go to this sample
project folder that we created and beginning because that environment has all the tools such as map
plot lib pandas Jupiter num pi etc..
We're focused on using Jupiter in pandas in this section so to activate that we're going to type in
Conda activate then I could copy this here and put it down there but we're going to practice typing
out commands in the command line because that's what we want to get proficient and used to typing these
sort of things.
The normal course sample project slash M will hit enter.
So now that is activated this and you can see we've changed from base to having this environment activated.
So if I load up a Jupiter notebook now by typing to put a notebook it's going to open up my browser.
Beautiful now because I'm in my home directory I need to look into my desktop and then email course
sample project.
There we are.
So now we're running this sample project folder within the Jupiter dashboard.
Now this is a project that we made in before and previous session where we created the example notebook
so to begin exploring pandas we're going to go new Python 3 notebook we'll give this a name we'll call
it introduction to pandas There we go into it so to begin with pandas the first step is to import pandas
as PD we've seen this a few times already but this abbreviation payday is just a short version of pandas
it saves us from having to type pandas continually so we'll hit shift and enter and this is just going
to tell python as a running Python 3 Hey Python go and get the pandas tool for us because we want to
use it and now the first thing to know about pandas is there's two main data types riding that little
hash this is a comment and I'll hit Enter the first one I'm going to look at is series so we go series
equals PD series and now remember where the style we're gonna we're gonna go through these concepts
is by looking at them first before discussing them because remember if in doubt run the code now if
I make a series here the command PD dot series takes a python list so I've got a few car brands in there
so we could really call this car brands if we want we'll leave it a series so let's hit shift and enter
and to view our series in Jupiter notebook we'll type in series hit shift enter so now we can see we've
got like a single one dimensional column of information that's the main thing you need to know about
series through series equals one dimensional so one column let's practice making another one hit escape
and create a new cell.
So what about this one we do some colors colors equals PDT not series Red we'll go blue and white excellent
so if we go underneath here and we'll put colors underneath so it displays it shift into beautiful.
So now we've got two one day series one dimensional.
When I say one day by the way one of car brands and one of different colors.
So now the difference between a series and a data frame now a data frame is two dimensional and data
frame is far more color common.
I'm saying column because data frames have columns a data frame is far more common than a series because
oftentimes with your data you'll have more than just one single column.
So let's create a data frame.
We'll call this one car data maybe car data equals PD dot data frame and now data frame is a little
bit different because it takes a Python dictionary.
So micro car make.
And then the beautiful thing about data frames is that we can create a data frame out of series.
So we've got series here.
So car make.
This is the key.
This is the value will go color and we'll give it our colors series so down here we'll go get car data
beautiful.
That is our first data frame.
Now this is so exciting right.
Because I love data frames and it's a beautiful thing to start seeing your first ever data frame being
made.
And now if you have a look here making a data frame from scratch can kind of be a bit tedious.
So what you usually do is rather than creating a data frame from some series you're going to import
data.
So we'll type that down and import data.
And now where would you get data say for example we wanted some car data.
Where could we find that.
Well if we go up to this beautifully created premade spreadsheet and by the way all the resources as
to what we're working on we'll be in the resources section we can see that this is a spreadsheet called
car sales.
And now how do you think we might get this into a panda's data frame.
That's right.
If you don't know the answer we haven't been through it yet but this is what panders is great at doing
right.
You'll have some structured data maybe in a spreadsheet or something which could be anything right.
This is car sales but you could have transactions you could have patient records something like that
but we want to rather than manipulate the data in a spreadsheet we want to start using code specifically
Panda's code.
So the first thing is we have to import it.
Now for this car sales data the way we could do it is to export it.
Now there's a little download tab here into commerce separated values dot CSC.
Now this is a very common data storage file type and panders works beautifully with it.
So if we were to export this spreadsheet data as comma separated values let's do that that's going to
save down here.
Now I've already imported this into my sample project folder as car sales dot CSC.
So let's see how we would import that in pandas.
So car sales equals PD don't read CSC and then we're going to type in the file name as a string.
So car sales dot CSC.
Now the beautiful thing about pandas or Jupiter notebooks in general actually is that you can use tab
auto complete.
So let's try that out.
So we're gonna press tab.
There we go.
And we've got some options here that's going to pre fill that.
So we don't want the missing data one we'll have a look at that in a future video but let's click that.
There we go.
Car sales don't CSP.
So all this is doing is saying hey pandas with PDA read this CSB file and save it to car sales.
So will it shift into now let's have a look at that data from beautiful.
So now we can see this is just the exact same information that's here in a panda's data frame.
Now the beautiful thing about this is that because it's now in a panda's data frame we can take advantage
of all the functions that pandas has to offer and manipulating viewing and changing this data.
All right let's have a quick overlook of what the anatomy of this data frame is because different places
refer to different things.
So we go to this slide the anatomy of a data frame so we'll break it down on the left hand side is the
index column.
Now pandas data frames like Python the list start at zero.
So if you had five rows in your data frame it would only go up to four member it starts at zero.
Now this here is a row.
So these all these values here including the index is called a row and these ones here are columns and
a row is referred to as access zero and a column is referred to as Axis equals 1.
So if you ever see a panda's function in the future which has a little parameter called access if it's
saying axis equals zero its meaning a row.
Now if it's saying axis equals one it means a column.
I got confused by this in the beginning I was just like just tell me if it's a row or column.
But some functions use axis zero or axis equals one.
Now these individual values here are data you can have different kinds of data types we'll see those
in a future video and the headings up here in bold are column names.
So these are the main things you need to know about a panders data frame.
You can take a screenshot of this or something like that.
It'll be in the resources section as well but if ever you hear me referring to different terms around
here you can always have a look at Europe the anatomy of the data frame and know what what's being talked
about.
Let's go back to our notebook.
And so once you have imported data from what you might want to do is make some changes here and then
export it.
So let's see how we would do that exporting a data frame.
Now of course we haven't made any changes to ours just yet but we're going to export it anyway to see
an example of how to do it to export a data frame.
We take the variable of the data frame car sales dot to CSC so to import it was read CSB.
Now we're gonna call this function car sales dot to CSC and then pass it a string name of what we want
to call it import export and car sales dot CSC.
Now you could also do car sales dot to excel if you wanted to export it to an excel file.
But since we're only really working with CSR vs which is kind of a universal data type you might not
have excel on your computer CSR vs you can run almost anywhere.
We're going to export to CSC.
So if we hit shift and enter what do you think that's gonna go let's go back up here.
We're looking here export and car sales don't CSP a few seconds ago.
Beautiful.
So now if we wanted to create a new variable exported car sales just to demonstrate PD don't read CSB
car sales now we want to export it car sales to all we're doing now is just reinforcing this file here
to see what it looks like and then we'll go export it car sales fix up this one as well.
Shifting into beautiful we import it back in but there's some unnamed column here.
Now this is a little trick of what to see as V does because as this index column here.
If you don't put in an index I think it's equals false.
If you don't put in this it'll export it with the index as a column.
So let's see what happens if we go that index equals false.
Now we're going to all that's done is re export of the file and we're going to re important.
There we go.
It's going to index it as it gets imported.
So that little parameter there index equals false is go.
Export this data frame.
And don't worry about throwing the numbers there but I think that's enough for now.
We've looked at the main takeaways from this is that pandas have two main data types series which is
a one dimensional column so there's only one column here data frame which is the far more common type
which is two columns or two dimensional sorry.
So you've got rows and columns.
But the more common way of importing data into pandas is to read something like a CSA v file and then
once you've made changes on this or manipulated in some way you can export it as a CSP file.
All right I'll see you in the next video.