‫Now we've got a little bit of an overview of what pandas is.
‫Let's start decoding.
‫So to begin, we're going to load up a terminal or command prompt.
‫Now, this is the workflow we've been through a couple of times now, but we're going to keep going
‫through it with each new concept to make sure we kind of get it down pat, because that's what we're
‫doing, right?
‫We're just practicing and practicing and practicing.
‫So if we try to access Jupyter Notebooks, which is our workspace where we want to use pandas, we run
‫this code whilst we're 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 on to my list, this will show me my environment.
‫And in my case, I want to go to this sample project folder that we created at the beginning, because
‫that environment has all the tools such as map plot, lib, pandas, Jupyter, NumPy, etc. and we're
‫focused on using Jupyter and pandas in this section.
‫So to activate that, we're going to type in Condor 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 you want to
‫get proficient and used to typing these sort of things.
‫EML calls sample project slash env and we'll 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 Jupyter notebook now.
‫By typing Jupyter 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 my course sample project.
‫There we are.
‫So now we're in the sample project folder within the Jupyter dashboard.
‫Now this is a project that we made in before and previous session where we created Example Notebook.
‫So to begin exploring pandas, we're going to go New Python three notebook.
‫We'll give this a name.
‫We'll call it Introduction to Pandas.
‫There we go.
‫Hit.
‫Enter.
‫And 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, PD, 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 because we're running Python three.
‫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.
‫I'm writing that little hash.
‫This is a comment and I'll hit enter.
‫The first one we're going to look at is series.
‫So we go series equals PD series.
‫And now remember where the style we're going to we're going to 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 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, but we'll leave it as series.
‫So let's hit shift and enter and to view our series in Jupyter Notebook Type in series hit, shift enter.
‫So now we can see we've got like a single one dimensional column of information.
‫And that's the main thing you need to know about series.
‫So series equals one dimensional.
‫So one column, let's practice making another one.
‫We'll hit escape and create a new cell.
‫So what about this one?
‫We do some colors.
‫Colors equals PD Note series.
‫We'll go read.
‫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 21d series, one dimensional.
‫When I say one D, 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 column 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 data frame.
‫And now data frame is a little bit different because it takes a a python dictionary.
‫So I go 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 and we'll go color.
‫And we'll give it our Colors series.
‫So down here, we'll go card data.
‫Beautiful.
‫That is our first dataframe.
‫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're usually do is rather than creating a data frame from some series, you're going to import
‫data.
‫So we'll type that down here, import data.
‫And now where would you get data?
‫Say, for example, we wanted some car data.
‫Where can we find that?
‫Well, if we go up to this beautifully created, pre-made spreadsheet, and by the way, all the resources
‫to what we're working on will 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 pandas data frame?
‫That's right.
‫If you don't know the answer, we haven't been through it yet.
‫But this is what PANDAS 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
‫PANDAS 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 comma separated values dot csv.
‫Now this is a very common data storage file type.
‫And PANDAS 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 carsales csv, so let's see how we
‫would import that in pandas.
‫So car sales equals PD read csv and then we're going to type in the file name as a string.
‫So car sales csv.
‫Now the beautiful thing about pandas or Jupyter notebooks in general actually is that you can use tab
‫autocomplete, so let's try that out.
‫So we're going to 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, carsales csv.
‫So all this is doing is saying, hey, pandas with PD, read this CSV file and save it to carsales so
‫we'll hit shift enter.
‫Now let's have a look at that dataframe.
‫Beautiful.
‫So now we can see this is just the exact same information that's here.
‫In a pandas dataframe.
‫Now, the beautiful thing about this is that because it's now in a pandas dataframe, 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 dataframe is, because different places refer
‫to different things.
‫So we'll go to this slide.
‫Anatomy of a dataframe.
‫So we'll break it down.
‫On the left hand side is the index column.
‫Now, pandas data frames like Python lists start at zero.
‫So if you had five rows in your data frame, it would only go up to four.
‫Remember, 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 one.
‫So if you ever see a pandas function in the future, which has a little parameter called axis, if it's
‫saying axis equals zero, it's 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 PANDAS 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 your
‫the anatomy of a data frame and know what what's been talked about.
‫So let's go back to our notebook.
‫And so once you've imported a data frame, 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 CSV.
‫So to import it was read CSV.
‫Now we're going to call this function car sales to CSV and then pass it a string name of what we want
‫to call it, import exported car sales CSV.
‫Now you could also do car sales to excel if you wanted to export it to an Excel file.
‫But since we're only really working with CSV ease, which is kind of a universal data type, you might
‫not have excel on your computer, see us vs you can run almost anywhere.
‫We're going to export to CSV.
‫So if we hit shift and enter.
‫What do you think that's going to go?
‫Let's go back up here.
‫We look in here, exported car sales, csv a few seconds ago.
‫Beautiful.
‫So now if we wanted to create a new variable exported car sales just to demonstrate PD read csv car
‫sales note we want to go export it car sales.
‫So all we're doing now is just re importing this file here to see what it looks like and then we'll
‫go export it.
‫Car sales fix up this one as well.
‫Shift and enter.
‫Beautiful.
‫We import it back in, but there's some unnamed column here.
‫Now, this is a little trick of what two CSV does because there's 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 there.
‫Index equals false.
‫Now we're going to.
‫All that's done is re-exported the file.
‫Then we're going to re-import it.
‫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 dataframe 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, DataFrame, 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 CSV file.
‫And then once you've made changes on this or manipulate it in some way, you can export it as a CSV
‫file.
‫All right.
‫I'll see you in the next video.