Welcome back.
Now I've got a Jupiter notebook running.
It's time to see what we can actually do in this notebook.
Remember in the last lesson we went through this this is like your standard menu bar.
This is a tool bar.
But we're going to avoid using the tool bar because we want to become experts at using our keyboard.
All of 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 while instead of clicking run on a cell so run is how you run some codes.
If you go here.
Now you want to print a nice message Hello world I'm learning about Jupiter.
No books.
We hit shift and enter we could have done that.
I'll see.
I've done that out of habit.
Right.
That's what we're going to.
We're going to be focused on is it rather than just learning how to use this toolbar to begin with.
We're going to be focused from a 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.
Remember I'm just got this cell highlighted pressing shift enter.
That's how you run a piece of code energy but a notebook.
Beautiful isn't it.
This this cell phone numbers going up all that's 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 and Jupiter where this is helpful is if you had something
like a equals five 14 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 into a is going to equal
six.
So these numbers are helpful to show us what order our notebook has been running.
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 Jupiter 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 in April 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 a 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 gonna 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 a keyboard because remember we're not getting used to
using this toolbar.
You guys all pretend it's not even there.
So to change from edits 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.
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 and in my experience and we're
going to press M for markdown and to think about that because to change it back to code is why.
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 setup so we want some data in our project folder and we want to run this
data through our workspace which is a Jupiter notebook and try to use some of these tools.
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 DuPont 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 Jupiter 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 heart disease.
Don't CSB.
How would we get that.
Now if you've never heard of V.
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 right.
If you don't know because you might not have ever gone through this before.
But what we're going to do is use panders to create a data frame D F stands for data frame rate CSP
and we're going to use the file name.
Now another beautiful thing about Jupiter notebooks is that if you have a file in here you can use tab
for auto complete.
So if we press tab it's going to pick up heart disease Delta CSP and we've already got the other inverted
commas.
So we're going to select this one.
So what is this line of code doing well it's going data frame equals PD so panders dot read CSB.
So this is a function and we're passing the file name heart disease dot CSP to the read CSC function.
We'll have a complete section on pandas later on but this is just to exemplify what you can do with
energy put a notebook.
So we're going to hit shift enter.
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 DuPont in notebooks is that you can view what you're working on straight
away.
So DLF dot head shows the first five rows of your data frame.
So look here we've got different columns we've got different examples.
Maybe we wanted to view the first 10 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 Jupiter
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 escape Double D for delete beautiful and go the following table shows heart disease information for
patients escape and press M for Mark down shift enter.
Now we've got some communication happening here.
OK.
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 looked like.
Because this is pretty confusing.
We're going to target column which is full of ones and zeros.
I only know that because I've seen this table four.
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 and go deaf dot target which just means access the target value of DLF.
We're going to go value counts which just means count the number of occurrences of different different
values in this column then dot plot which means create a plot of kind.
We got that mixed up colon bar which just means let's create a bar graph.
See hit shift enter by the way.
Why didn't that show up well Matt bluntly I've got access.
Mm hmm.
We go back to our little environments set up here.
We've been using pandas to look at this data frame.
But we need map plot lived to look at graphs.
Okay.
No reason I know that it's because I've had experience but we're gonna have a look at each of these
tools in depth.
So what could we do here.
Maybe we try to go import that plot lib dot pie plot as BLT party as a shortcut from that plot lib or
hit shift into nothing happens.
Why is that.
Well remember Jupiter 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 is 24 and this was 23 running this piece of code didn't effect this until we reran
it.
So that's a very important thing to think about with Jupiter 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.
OK.
If I can run code cells as well as tech 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 and we're going to use exclamation mark if you've never written markdown code before there
are 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 Jupiter cell.
So we're going to we want to import the image that we uploaded earlier that page and you can do this
with any image.
So this is within this file folder here we're just writing 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 into.
There we go.
So this is our framework.
OK.
We've seen this before.
Now what we might do is create a section for each of these steps so you could do mark down again escape
M number one problem definition where we could say predict heart disease.
I'm typing out something small here you might want to do something longer and then we could have a Skype
BBB to create five or six cells for I can't really count two data.
This is the data we're using we're going to hit escape M and then shift into.
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 and we could look at the features of our data.
We could do some modeling and then we could run experiments all of this from within a Jupiter notebook.
Now there's one more thing before we finish up this lecture because getting a bit long that you can
do with energy Jupiter notebook the main to take away 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 Jupiter notebook.
So say for example we wanted to run less just as if we are running less on the terminal.
So if I go here and I put in a less it's going to list all of the files in my user account if we do
the same in Jupiter notebook if we just ran less in a code cell and hit shift center.
That's interesting.
That might be an update.
I haven't seen before.
Usually you'd have to type in exclamation mark Ellis.
Well there you go.
You'll learn something new every day.
Maybe you don't need the exclamation mark but generally to run a command like l s like list you would
need the exclamation mark in front of the terminal command.
And what this is going to do is go into 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 L S command is just showing us the different files that we have here.
All right.
Well that's enough for this lesson.
Remember sound like a broken record here but this is important to take away is that Jupiter notebooks
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 mark 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.