Well, in this lecture, I'll show you how
to set up the Jupyter Notebook, or
Jupyter for short, and also how to use
it. So far, you've worked both with a
Python or an IPython Interactive Shell.
But also you've worked with an editor,
such as Atom. Sometimes, you may have the
need for a hybrid between an interactive
shell and an editor, when you want to
test things out, but you also want to
save your blocks of code that you're
writing. Because an interactive shell is
great for testing things quickly. But
you can save the code, and the editor is
good for saving the code, that is not
great for testing things. But I can tell
you that Soldier Hubert tool exists,
and that is called Jupyter Notebook, and
that is an amazing tool that will boost
your productivity, and Jupyter is
especially good when you're working with
data, as it's a great environment to
explore data, and you'll see its
usefulness in just a bit. Of course, you
still want to use editor, such as Atom,
when you're working with multiple Python
scripts that interact with each other.
That's the case of web application. For
example, when you're developing web
applications, you'll have to deal with
multiple Python scripts, and also HTML
files, CSS, and other files as well. We'll
build web application later in the course,
and you'll see how Atom is good for
that. But for data, use Jupyter, so
Jupyter, let's see how to install it.
Well, we can go to the installation, so
install, and you can go through these
instructions. But instead of going
through this advice, you actually to use
your command line to install Jupyter and type in
pip install jupyter.
[No audio]
So that will download Jupyter and it will install it
in your system, and then to start a
Jupyter session, a good practice is to
go to a folder,
[No audio]
let's say test3,
and here you can open a command prompt,
[No audio]
and then you type jupyter notebook.
[No audio]
Now, that will open a Jupyter session in the browser.
So the Jupyter Notebook is actually a
browser notebook. The reason I opened
the Jupyter notebook in the command line
was that, at least on Windows when you
do Shift, and then right click on a
folder, your command prompt is opened in
the current folder. So in this we are here,
and then when you create a notebook
file now, every file will be saved in
this directory here. Alternatively, you
can open your command prompt everywhere
you want, and then you can cd to the
folder where you want to save your
Jupyter Notebooks. All right, now,
we don't have anything here. So what
you're going to do is Create a notebook.
And we install Jupyter as Python
libraries, so on the notebooks, we have
Python 3 available. So the kernel
will be Python 3. If you have
associated other languages here, you'll
see them under here on their
notebooks. So this is an empty
notebook, and this is the name of
the Notebook, and you can change these to, let's
say, Testing, press OK, and if you go to
the folder, you'll see that file with
Testing name and IPython Notebook
extension was created. So that is
created automatically every time you
type something here, you do some
changes or something. Now let me show
you how you can work with IPython
Notebook. So you can consider every cell,
oh this is a cell, and you can consider every
cell as a line in normal Python
Shell. But here in this shell, you can
actually write multiple lines of code,
let's say print 1, and then if you
don't want to execute it this right
away, you can press Enter. So with
Enter, you enter a new line in the cell,
and then print 2, and so on, and if you
want to execute the cell now, you can
press Ctrl Enter, and you get the
output. Now if you want to create a new
cell, Alt Enter would do that, and here
you can write another block of code.
[No audio]
With Enter, you go to the next line, and
so on and if you want to go to the next
cell right away, so before we pressed
Ctrl Enter, now you can press Shift Enter
and you go to the next cell
automatically, and with Shift Enter, you
can, you also execute the cell where you
are working on, you can create new cells
with Alt Enter, and you can deal with
them by pressing first, you press Escape,
and then you press DD two times, DD
again, so it's quite flexible. Something
you should notice is that we have two
modes. Basically, we have the command
mode. So when you are in the command
mode, you see a gray rectangle around
the cell, and when you are to go to the
edit mode, then you press Enter. So
while you are focused on the
current cell, the press Enter, and then
you edit the cell. So in edit mode,
when you type things, you're
inserting text in the cell, you're
inserting code in the cell, Escape
and command mode, DD and you delete the
cell, Alt Enter, and you enter a new cell.
[No audio]
So these are the most used
shortcuts, keyboard shortcuts. But if
you want to know more shortcuts, you can
go to Help, and then Keyboard Shortcuts,
and then you see a list here.
[No audio]
But these are good to get started. When you're
done with this, you can just close the
tab, and you can also close the
directory tree here. So notice that
Jupyter actually opens in a localhost
session, and if you want to open again
your notebook, so you can go here again
and go to Open command window here and
jupyter notebook,
[No audio]
and here is the file,
and is just as we left it. Now, a
Jupyter Notebook is best to use for
doing explorations, and especially, data
explorations. So if you're working,
let's say with data analysis or data
visualizations, the Jupyter Notebook
is perfect to use. You can use the
Jupyter Notebook, for example, to load a
table of data in the session. For that
you'd use pandas.
[No audio]
So you import the library, you press Enter, or Shift Enter
to go to the next cell, and you press
Enter again to write something. So let's
say df equals to pandas.read_csv.
[No audio]
And I have csv file somewhere in my system.
[No audio]
Press Enter and
[No audio]
Wow, so you get a nice HTML
table which was loaded from the csv
file, and you can also plot graphs in
the Jupyter Notebook. So that's also
something you're learning in the course.
And so data analysis on visualizations,
you can also use the Jupyter Notebook
for web scrapping and that is very
convenient, because you would have this
blocks of code and then you have to
continuously tweak the code. So you may
want to change something here, then you
get a nice display, not this one
exactly because this is a messed up stream,
but this one, for instance, you have a
slider here so you can scroll up and
down, you know, inside a separate window that
doesn't affect your general, your main
window. So I hope you have you've gotten
a good idea of the Jupyter Notebook.
Just take a note of the shortcuts, of the
keyboard shortcuts to execute code the
editor and the command mode, you know,
Enter, Escape, and Enter again, and so
on and so forth, and you just
practice them a little bit and you'll
get used to with Jupyter very
quickly. See you in the next lecture.