‫Welcome back.
‫Okay, now I've got a Jupyter Notebook running.
‫It's time to see what we can actually do in this notebook.
‫So, remember, in the last lesson we went through this.
‫This is like your standard menubar.
‫This is a toolbar.
‫But we're going to avoid using the toolbar because we want to become experts at using our keyboard.
‫All of the the things here that you can do like saving, adding, cutting, copying, pasting, etc.,
‫you can do with the keyboard.
‫So what will this save you?
‫Well, instead of clicking run on a cell.
‫So run is how you run some code.
‫So if we go here, maybe we want to print a nice message.
‫Hello world.
‫I'm learning about Jupiter notebooks.
‫We hit shift and enter.
‫We could have done that.
‫I'll say I've done that out of habit.
‫Right.
‫And that's what we're going to be going to be focused on, is rather than just learning how to use this
‫toolbar to begin with, we're going to be focused from the start on using the keyboard so I can keep
‫pressing run here or I could keep pressing shift enter.
‫And now what you might be noticing is that the number on the left is going up every time I hit shift
‫and enter.
‫So remember I've just got this cell highlighted, pressing shift.
‫Enter.
‫That's how you run a piece of code in a Jupyter notebook.
‫Beautiful, isn't it?
‫And this this cell numbers going up.
‫All that saying is that this is a 13th cell.
‫Remember, this is a cell.
‫Could be code or markdown.
‫We'll see that in a second.
‫This cell or there have been 13 cells run in total in Jupyter where this is helpful is if you had something
‫like a equals 514 and then you go a.
‫We didn't mean that a equals six.
‫So what does what do you think A equals now?
‫Because this is 14 and this is 16.
‫If we hit this and hit shift, enter.
‫I is going to equal six.
‫So these numbers are helpful to show us what order our notebook has been run in.
‫So for example, if we had 100 of these different cells with different information, in an ideal world,
‫a notebook is run from top to bottom, but in some cases you might be working on a project and run a
‫cell up here and then rerun it down here.
‫And later on in your notebook, a few hundred cells down.
‫You've got some kind of error.
‫This is what you can use to figure out what order your your notebook was run in.
‫Now, because we've got code here, we can run all of Python's functionality from right in the Jupyter
‫Notebook shift into one plus two.
‫You'll notice some cells have in and some cells have out.
‫Now, if a cell has an output like some sort of code output, it will usually have an outnumber the
‫outnumber matches in number.
‫So this is just saying, hey, there's some input code here and we've got some output code here.
‫Now, we did have a brief look at this before code and markdown.
‫This is where the absolute beauty of Jupiter and Opal comes into play is that you can have code and
‫formatted text, which is what markdown is within the same notebook.
‫Let me show you an example.
‫So we wanted to start our project called Heart Disease Project.
‫And remember, Jupiter Notebooks are the workspace of your data science projects.
‫So you can run machine learning code and describe what you're doing right from The Notebook.
‫We're going to see this in practice throughout, but I just want to highlight what turning a cell into
‫markdown does.
‫So we can change that to markdown.
‫But remember where we don't want to get used to using the toolbar.
‫So how do we do that?
‫Well, another beautiful thing about Jupiter is that the cells have two simple modes.
‫One is called edit, and you'll notice this little pencil up here and this green box around it.
‫The other is called command mode.
‫Now, how do we switch between the two?
‫Well, as you might have guessed, we can also use the keyboard, because remember, we're not getting
‫used to using this toolbar.
‫You might as well pretend it's not even there.
‫So to change from edit to command mode, we're going to press escape.
‫Beautiful.
‫Now we notice that the little green bar has changed to a blue bar and the pencil has gone away.
‫Now, before we run this cell, how do we get back to edit mode?
‫To do that, I press enter.
‫Now we get our green box back and the little pencil comes back.
‫Excellent.
‫But we actually want to be in command mode, so we'll go back.
‫Escape blue box is back, pencil is gone.
‫You'll get used to running this escape and enter after you've had some experience.
‫I just know how to do these things because I've run thousands of cells in in my experience.
‫And we're going to press.
‫M for markdown.
‫I had to think about that because to change it back to code is y.
‫So watch this little box up here while we're in edit command mode.
‫Sorry.
‫With the blue box we can press m for markdown or y for code, but we want markdown in this case m and
‫to run this cell, we're going to hit shift enter.
‫Now you see, this is some nicely formatted text.
‫So what you could imagine in the future is for a project, you might start it off with a heading up
‫here and then you might add some information below it.
‫So this project is about classifying whether or not a patient has heart disease.
‫So this is how you can start to communicate your work right from the right, from the very beginning
‫of a project.
‫Now, what else could you do here?
‫Well, let's let's see some data.
‫If we go back to our keynote, we want to set up this kind of set up.
‫So we want some data in our project folder.
‫We want to run this data through our workspace, which is a Jupyter Notebook, and try to use some of
‫these tools.
‫Well, let's get a little taste of that.
‫So if we go here, import pandas as PD, what this is saying is this is code.
‫It's telling Python to go, hey, python, go and get pandas imported as the shortcut PD, which is
‫very common for pandas.
‫We'll see a little bit more of pandas in a future video.
‫What I'm doing is exemplifying the different types of things you can do in a Jupyter notebook.
‫And please, if you're following along, make sure you're typing this code out by yourself.
‫But if we go type this line of code and hit shift enter, what that's going to do is import pandas to
‫this notebook.
‫So now we have access to use pandas, which is one of the tools we installed in our environment within
‫our workspace, the Jupyter Notebook.
‫So do you remember in the last lesson how we uploaded some files here?
‫How would we get these files?
‫So this is a hot disease?
‫CSV.
‫How would we get that?
‫Now, if you've never heard of CSV, it's a format called comma separated values.
‫It's very common way to store data.
‫But how do you think we'd get that into here?
‫That's alright if you don't know because you might not have ever gone through this before.
‫But what we're going to do is use pandas to create a dataframe.
‫A DF stands for DataFrame.
‫I'm going to read CSV and we're going to use the file name.
‫Now another beautiful thing about Jupyter Notebooks is that if you have a file in here, you can use
‫tab for autocomplete.
‫So if we press tab, it's going to pick up heart disease.
‫CSV and we've already got the other inverted comma, so we're going to select this one.
‫So what is this line of code doing?
‫Well it's going dataframe equals PD.
‫So pandas dot read csv.
‫So this is a function and we're passing the file name heart disease dot csv to the read CSV function.
‫We'll have a complete section on pandas later on, but.
‫This is just to exemplify what you can do within a Jupyter Notebook.
‫So we're going to hit shift into you can see that it's run because that number has gone up, but how
‫would we view our data?
‫So another beautiful thing about Jupyter Notebooks is that you can view what you're working on straight
‫away.
‫So DF Head shows the first five rows of your dataframe.
‫So we look here, we've got different columns, we've got different examples.
‫Maybe we wanted to view the first ten to get a better look.
‫There we go.
‫We'll have a look at this in a in a future project.
‫But this is just to show you what kind of data Jupyter notebooks can display.
‫So we might even put a cell in here.
‫So we go escape B for a new cell below.
‫You can also press A for a new cell above, but we're going to remove this one.
‫So we're escape double D for delete.
‫Beautiful.
‫Let me go.
‫The following table shows heart disease.
‫Information for patients.
‫Escape and press m for markdown shift enter.
‫Now we've got some communication happening here.
‫Okay, well, we've seen a table.
‫What if we wanted to to maybe put in a little graph or something like that and see what this information
‫actually looks like?
‫Because this is pretty confusing.
‫We've got a Target column which is full of ones and zeros.
‫I only know that because I've seen this table before, but one means someone has heart disease and a
‫zero.
‫You can't see any on this at the moment means someone doesn't have heart disease.
‫So what if we wanted to graph that quickly and have a look at at how many patients have heart disease
‫and how many don't?
‫And each row here, by the way, is an individual patient.
‫And so these are their parameters.
‫Let's have a look.
‫We can go def dot target, which just means access the target value of DF.
‫We're going to go value counts, which just means count the number of occurrences of different, different
‫values in this column.
‫Then don't plot, which means create a plot of kind.
‫Oh, we've got that mixed up con bar.
‫Which just means let's create a bar graph.
‫Say you hit shift enter, by the way.
‫Why didn't that show up?
‫Well, Matt, bluntly, I've got access.
‫Hmm.
‫We go back to our little environment set up here.
‫We've been using pandas to look at this data frame.
‫But we need map plot lib to look at graphs.
‫Okay.
‫And the reason I know that is because I've had experience, but we're going to have a look at each of
‫these tools in depth.
‫So what can we do here?
‫Maybe we try to go import map, plot lib dot pie plot as plot.
‫Plot is a shortcut for map plot lib.
‫We hit shift enter.
‫Nothing happens.
‫Why is that?
‫Well, remember, Jupyter, notebooks are executed in order of operation.
‫So just because we ran a cell down down here doesn't mean it's going to influence the cell up here.
‫So what we'll have to do is come back up here and rerun this cell.
‫There we go.
‫So now if we look at the numbers in 24, in 25, out 25, you see what just happened there?
‫Because we ran this cell before as 24 and this was 23 running this piece of code didn't affect this
‫until we reran it.
‫So that's a very important thing to think about with Jupyter Notebooks is that they're executed in order
‫of operation.
‫And so the other takeaway here is that not only can we look at our data in a table format, we can start
‫to look at it in graph format.
‫So you might be starting to see here, okay, if I can run code cells as well as text cells as well
‫as image cells, I could do my entire project from within this notebook, which is exactly right.
‫See, one more thing.
‫And that's if we wanted to import another image.
‫So we'll change this cell to mark down escape.
‫M We're going to use exclamation mark if you've never written markdown code before, there's some great
‫guides online on how to write markdown code, but essentially any kind of markdown code you can write,
‫you can write in a Jupyter cell.
‫So we're going to we want to import the image that we uploaded earlier.
‫Dot png and you can do this with any image.
‫So this is within this file folder here.
‫We're just rotting it here.
‫You can do this with your own image.
‫Basically what this is, is markdown code for saying import this image to the notebook.
‫If we hit shift, enter.
‫There we go.
‫So this is our framework.
‫Okay.
‫We've seen this before.
‫Now, what we might do is create a section for each of these steps.
‫So you could do markdown again.
‫Escape M.
‫Number one problem definition where we could say predict heart disease.
‫I'm typing out something smaller here.
‫You might want to do something longer.
‫And then we could have a Skype baby to create five or six cells.
‫For.
‫I can't really count to data.
‫This is the data we're using.
‫We're going to hit escape M and then shift enter.
‫So now you can start to imagine we've got our framework.
‫We could start off with a problem definition.
‫We could then look at a data just like we've done here.
‫We could move this down to the data section, then we could create an evaluation metric, then we could
‫look at the features of our data, we could do some modelling and then we could run experiments.
‫All of this from within a Jupyter Notebook.
‫Now there's one more thing before we finish up this lecture, because we're getting a bit long that
‫you can do within a Jupyter Notebook.
‫The main two takeaways so far is that you can run code text and images all within the same space.
‫And the final thing is that you can also run terminal commands from within a Jupyter Notebook.
‫So say for example, we wanted to run LZ just as if we were running LZ on the terminal.
‫So if I go here.
‫And I put it in LZ.
‫It's going to list all of the files in my user account.
‫If we do the same in Jupyter Notebook if we just ran LZ in a code cell and hit shift enter.
‫Oh, that's interesting.
‫That might be an update I haven't seen before.
‫Usually you'd have to type in exclamation mark.
‫LZ.
‫Well, there you go.
‫You learn something new every day.
‫Maybe you don't need the exclamation mark.
‫But generally to run a command like LZ like list, you would need the exclamation mark in front of the
‫terminal command.
‫And what this is going to do is go in Jupiter instead of executing this command like some python code,
‫execute it because it's got the exclamation mark there as if I was running it on the terminal like this.
‫And so the LZ command is just showing us the different files that we have here.
‫All right, well, that's enough for this lesson.
‫Remember, I'm sounding like a broken record here, but this is important to take away, is that Jupyter
‫Notebook cells are run in order of the number.
‫So if we ran here a equals five, if we came down to this one and skip this one, it's going to be a
‫equals five.
‫But then if we ran this.
‫I would equal six.
‫And you can run mock down cells, code cells as well as.
‫Plot, different images all within the notebook.
‫We're going to have plenty of hands on experience with this throughout the rest of the course, so stay
‫tuned.