Well in this lecture I'll show you how to set up the Jupiter Notebook or Jupiter for short and also
how to use it.
So far you've worked both with Python and an iPython interactive shell but also you work 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 just save your blocks of code that you were writing because
an interactive shell is great for testing things quickly.
But you cant save the code and the editor is good for saving the code but it's not great for testing
things.
But I can tell you were that such a hybrid tool is that it's called Jupiter Notebook and that is an
amazing tool that will boost your productivity.
And Jupiter 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 a 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 well build a web application later of course and you'll see how Atom is good for that.
But for data use Jupiter.
So Jupiter, let's see how to install it.
Well we can go to the instalation so install and you can go through these instructions.
But instead of going for this advice you actually to use your command line to install Jupiter.
Typing pip install Jupiter.
So that will download Jupiter and it will install it in your system. And then to start a Jupiter session
a good practice is to go to a folder.
Let's say test 3 and here you can open a command prompt and then you type Jupiter Notebook
That will open
a Jupiter session in the browser. So the Jupiter an old book is actually a browser notebook.
The reason I opened the Jupiter notebook in the command line was that at least we know so when you do
shift and then right click on the folder your command prompt is opened in the current folder.
So in this one 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 Jupiter Notebooks.
All right.
Now we don't have anything here.
So what you can do is create a notebook and we installed Jupiter as Python Library so under notebooks
we have Python 3 available.
So the kernel with the Python 3 if you have associated all the languages here you'll see them under
here on their notebooks.
So this is an empty notebook.
This is the name of a notebook and you can change it to let's say testing.
Press Ok.
And if you go to the folder you'll see that a file with testing name and iPython notebook extension
was created so that it's created automatically every time you type something you do some changes or
something.
Now let me show you how you can work with the iPython Notebook so you can consider every cell of This cell
and you can consider every cell as a line in you know normal Python shell.
But here in this trial you can actually write multiple lines of code let's say print 1 and then
if you don't want to execute this right away you can press enter.
So we 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't press Control Enter and you get the output.
Now if you want to create a new cell ALT enter it would do that.
And here you can write another block of code.
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 Control Enter now you can press Shift Enter and you go to the next cell automatically.
With Shift Enter
you also execute the cell what are you working on.
You're going create new cells with ALT Enter and you can deal with them by pressing first you press
Escape and then you press dd 2 times dd again.
So it's quite flexible.
Something you shouldn't notice is that we have two modes.
Basically we have the command mode.
So when you are in the common mode you see a gray rectangle around the cell and when you are to go to
the edit more then you press Enter.
So while you are focused on the current cell you press Eneter and then you edit the cell.
So in edit mode when you type things you're inserting text in the cell.
Youre inserting code is in the cell. Escape and common mode.
Dd and you delete the cell. ALT Enter and you enter a new cell.
So these are the most used short cuts, 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.
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 Jupiter actually opens in a local host session.
And if you want to open again your notebook you can go here again and go to Open Command Window
here and Jupiter Notebook.
And here is the file and it's just as we left it.
Now a Jupiter notebook is best used for doing explorations and especially data explorations.
So if you're working with data analysis or data visualizations the Jupiter Notebook
is perfect to use.
You can use the Jupiter Notebook for example to load a table of data in the session.
And for that you'd use Pandas.
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.readcsv.
And I have a CSV file somewhere in my system.
Press Enter and Wow.
So you get a nice HTML table which was loaded from the CSV file and you can also plot graphs in the Jupiter
Notebook.
So that's also something you're learning in the course.
So data analysis and visualizations.
You can also use the Jupiter Notebook for web scrapping and that is very convenient because you
have these blocks of code and then the you have to continuously tweak the code so you may want to change
something here and 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 you or general
your main window.
So I hope you have gotten a good idea of the Jupiter Notebook. Just take a note of the shortcuts
all the keyboard shortcuts to execute
code the edits 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.
You'll get used with Jupiter
very quickly. See where the next lecture.