Jupyter Lab Tutorial - Fully Interactive!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
most of the code that you will be writing during this course and also as a professional type and data scientist will be written in a Jupiter environment Jupiter is an interactive code environment it will let you write code and get emitted feedback from it so you don't have to follow traditional process of writing it in a regular text file executing Python and trying to understand what went wrong when something fails or getting partial results so it's a it's the de factor it's the most common and more popular most popular environment for data science in Python it's also transcending the data science space we actually for example use it a lot in a regular Python data science boot camp for people getting started with programming we give them a very good introduction to programming with Jupiter because again it's interactive it has automatic like an immediate feedback that's gonna give you an overview of how your code works and how it's being executed usually to get Jupiter installed you have to just get a couple of tools and account Minicon using paper you have to use these external tools and it gets a little bit complicated so we have actually we're using a new online environment which is called notebook stuff ai and basically it contains all the Jupiter environment online it's like a Google Drive version of Jupiter notebooks and it also one important feature is that it doesn't just include Jupiter notebook it also includes the new version which is Jupiter lab which is what you are saying right here it's it's a it's a it's the evolution of regular tubular notebooks is a complete data science environment and it's all available again online in notebooks top AI so this will be the surface it we're using we're actually hosting all our code here so anybody can fork it and work with it so just to give you an idea of how this thing works basically the idea of a jupiter environment is that it will have these notebooks that i have just one here created in this particular project if you fork it you're gonna find this tutorial that has a lot of details I will start here just in a blank one and these notebooks are a set of multiple cells as you can see here in which you will be able to write code so you can write code and interpret it and run it automatically are actually sorry immediately and get instant feedback about what's going on this is all valid Python code right this is this isn't anything special it's just regular Python code which is run executed and you get the feedback middlee about it so for example if I define a variable like x equals two and i do x times 3 this is all valid Python code I can keep executing these and the variable X is defined so it's again all that you can expect about Python we actually have a video about Python in the next section if you need a little refresher about it so this cells can take two formats or they can actually take different modes the default one is code mode which again execute whenever you execute the cell whenever you run it and I'm going to show you how to do that whenever you run this cell it's gonna run Python code there is also a text-based mode a rich text based mode which is marked down so I can change the mode here you're gonna read a markdown I'm hearing in a red coat martin code is not only text so for example if i do two plus two this is text but it's not just text but also it's rich text you can add titles you can add images you can use paragraphs you can use pretty much whatever you want so let me do these here's our title there you go and actually you have a pretty good preview of all the great features you can include it here so images quotes italics balls linked it's all supported with the market markdown modem what these will allow is for you to include these markdown this rich text within your code so your notebooks will be a combination of pretty like readable beautiful markdown mode with with documentation about your project images explanations conclusions and also of Kotick of course the code that you used to run and all these notebooks they can be exporters into for example formats like PDF so you can have a fully functional notebook which runs a report every day right combined with this beautiful markdown based code and you can export these notebooks once per day and have this report are the updated pretty much daily right without any effort because again it's a combination of text on your Python code so this is unknown this is just a notebook and it's what used to be the regular driven notebooks environments you can see here this tiny notebook with this improvement of the lab this is actually two Perl lab the environment grew a little bit more powerful and it's not just about a notebook but it's also full interface that gives you access of regular machine working in the cloud so right here where they have is for example I can launch a terminal and this is fully functional Python sorry Linux machine running in the cloud so I can install any packages that I need I can do any reporting logging anything that I need to do I can do it with this machine aside from that it also gives you access to a file explorers or these are the files of my project right and you can also access a very simple just editor so right here I could create a Python file I can rename it to something like utils of Pi and I also have a regular just editor right here that hello world it works as expected so this is all part again of your Jupiter and varmint Jupiter lab environment we'll go focus of course on notebooks which are these special files that have a I PI and B their extension which stands for ipython notebook this used to be called - notebooks so let's focus focus 100% on these notebooks and again I'm gonna get started with it whenever you start a notebook it has what it's called a kernel running behind the scenes that it's executing your code so it's like these robot that it's sitting behind scenes and listening to your commands and running them with again a folder functional types and just compiler if you ever have issues with these kernel you can always resort it here you have a list of all the kernels that are running so for example here I have my variable X that it's running I can shut down this kernel the one of untitled dot I pine we and now if I try running X nothing is happening because there is it says no kernel so I can restart it I'm gonna restart the kernel kernel has been restarted I can sit here and now if I try running X again it doesn't exist because again the kernel has just been restarted and I have lost all the previous date so usually we try these notebooks to be kind of a sequential structure of all our code we try to write it top down so we can always replay it right from the top it's also good to have some sort of for like other documentation self documentation you can read the process you've that you're taking right and the code you have top to bottom and you can understand that the steps that you took and pretty much all the decisions you made if you keep a very it's usually recommended we recommend it to have a tidy notebook and organized notebook top to bottom right in which you can just at any point scroll up and start reading all the processes or all the steps that you took okay you bring someone else a third person and just make them read your code and it should make sense top to bottom so let's actually talk about these cells this cells again can have multiple modes we're gonna focus in code first we you saw the markdown I encourage you to for example whenever you see markdown mode like right here if you double-click and go to edit mode you will be able to see what's the internals track of the markdown so this is why you include an image you can include titles etc so we will not pay a lot of attention to markdown will be focus especially into code and the interaction with cells so this is something important at the beginning a cell can have or this notebook can have two important modes command mode which doesn't make a lot of sense on now it doesn't tell you much and also edit mode the difference is that as you can see there is no cursor here if I click inside the cell you will see now that the cell becomes active and the cursor right is present what's the difference in command mode without the cursor if I click for example my up and down arrow keys I'm going to get I gonna - I'm going to be moving across all these cells if I'm in edit mode and I have multiple lines just let's make multiple lines here if I of course hit the up and down arrow keys I will be moving up and down as you might be expecting so that's the first thing we have again an edit mode and a command mode usually we don't use a mouse with no books we prefer to use the keyboard as much as possible you can write all your code without using your mouse using 100% your keyboard it does take time to get used to the commands but it's gonna be a significant speed up of your development workflow so how can you transition from edit mode to command mode and back again to edit mode well with the Escape key and with the return key so if I hit escape I'm hearing the Edit on the edit mode the cursor is there if I hit escape I'm going to go back again to command mode if I hit return or enter I go back again to edit mode so escape to go to command mode return to go back again to edit mode there are many more shortcuts and we will be discussing them but just as a reminder or as an important note for you there is this commands palette that is gonna give you a summary of all the commands we're gonna run and a reminder of the shortcuts that you need right so for example enter command mode you can just follow the the commands here this max it's a little bit weird you can always google edit mode is with enter so I hit here I just hit enter and I go back again to command mode if I hit escape I go back again to the command mode so most of the commands the book will be running today are of course base of the command mode so whenever I tell you for example we're gonna do we're gonna see what's the command to create a new cell so I have only one cell how can I create a new cell well I'm gonna tell you the command but you have to be in command mode to do it alright so always keep in mind that to run this commands to modify cells you have to be in command mode so let's make let me put something here hello world there you go I'm gonna show you how to create cells first with your keyboard you can create cells with a plus button this is pretty obvious but I want to focus again on the keyboard so you can speed up your development workflow how can you create a cell will actually have to first define what position you want to give to that cell alright so let me actually create a new so here we're going to put x equals 1 and it's gonna be a python cell so it's gonna make a little bit more sense so where do we want to place our cell if I want to put it above the current one if I want to create a new cell above I'm gonna hit the a key so just hearing a here will create the cell above I can create as many cells as I want and as you can see they're all creative above so let me delete them I'm gonna show you how to delete them later what if I want to create a cell below well I will hit the B key and I keep creating cells below the current one how can I delete a cell well once you have created one you have to hit the D key D from DICE you have to ple hit the Delete key the D key two times so I do TV and I delete the current cell usually what I am saying right here it's the current cell so that is indicated by the current selected cell so you can go up and down and select the one you want to delete for example this one I'm gonna go back to command mode I'm gonna hit the D key two times and this cell is deleted what happens if you delete something or if you want to undo a certain action in this case I just realized that I didn't want to do that I didn't want to delete that key you can always undo your work with the z key I just hit Z and I get back again I did the cell that I delete it I get the previous action undone so for example if I create here a new cell and F a I hit Z that cell is uncreated basically it's destroyed so Z is going to undo that command you can also copy and paste cells so you can for example here I want to copy this cell and I want to paste it below the commands to do that is first you will move to the selected cell and you will hit that C key from copy C that's it I'm then you get a position yourself whatever you wanna paste that cell and you're gonna just keep hit sorry the V key so V from command V control V and you're gonna paste that new cell that you have and that is it these are the most common commands that we need to month to manage to create delete etc our keys we're gonna see now how to run commands once we or execute cells because it doesn't have to be come in basically whenever you have a key so let's sorry a cell in this case gonna be a code cell you can execute this cell just by doing hitting the play button but again I want to show you I want to focus on the keyboard so if I want to execute this cell I have two different modes the first one is gonna execute the cell and the focus will remain on the current cell and to do that I will hit I will maintain press the control key underneath and I'm gonna hit the return key so it's control return or control enter on again as you can see the code is executed but the focus stays on this same cell if I want to execute the code and move to the second cell what I'm gonna do is hit their Shift key keep it pressed the shift key and hit the return key or the enter key so it's basically shift enter to run the code and move the focus to this next cell as you can see the focus is now here so we've seen how to manage ourselves we have also seen how to run the code these code running process can also be applied to markdown cells so for example if I set these cell a smart down I create a title to actually compile if you want the markdown you can do the same thing control return or shift return it's gonna ship the shift sorry the focus to the next cell you can change the mode of a cell with the Y key so I hit the Y key and I go from command sorry it's from markdown to code with the Y key is gonna turn a cell into code the M key from markdown is gonna turn it into markdown so y2 code M - Martin you can transition you can cycle back and forth between these two again remember that these cells they are these ya these cells are always 1 you hit whenever you run a command they are pretty much sending the request to a hidden colonel that it's running behind the scenes right and the colonel will execute these commands you can always shutdown the Colonel's and not that will pretty much shut down and kill all your current status so if you have any cells or any code that you don't that is not preserved as a cell you will be losing it so be aware of that you can also interrupt the chorus it's writing as it's running in a Jupiter environment so right here what I'm gonna do is do something like for example I'm gonna do while true I'm gonna do here import slip your wall and port I'm sorry while true print hello I'm gonna do time dot sleep one second or three seconds actually so I'm gonna get this thing running and as you can see the the code has this asterisk here or the cell has this Asterix here which means that the current cell is create the cell is currently or it's still executing it's still running and it's looking or Colonel I can't run any other cell right if I do two times two here that will not be a run because these one is holding on our current colonel it's blocking it so sometimes you need to stop these cells or to interrupt these cells one thing you can do is use this command that it's just to interrupt the colonel there we go and it's the same as to in control C with your keyboard and now this cell will be run or the shortcut the keyboard shortcut to interrupt the cell is hitting the i key from interrupt two times so I do i I and it sends a keyboard interrupt to the current cell so the colonel is again released the advantage of jupiter notebooks is that it will again combined not just regular code from Python but it will also be very useful for example for visualizations so in this case I'm gonna show you this is just some code we have in this tutorial if wanna follow follow it I'm gonna create a visualization it's displayed right within our notebook don't worry we have an entire lesson about visualizations if you want to check them later this is just again remember this is just an introduction to jupiter lab so you can understand how it works so again we also have a quick introduction to Python if you need a refresher the rest it's all about data science the idea of this quick lesson was to show you how to use notebooks and for you to get familiar our recommendation here is to try to use the keyboard as much as possible so if you don't remember the command just go to the palette it's gonna do something run right run selected cell it's going to tell you which command you have to use for example run selected cell run select and cell and don't advanced advanced sorry it's what we did here the focus stays here run select and sell an insert below is the shift one shift enter it moves the focus below if there are no cells below it will create a new one automatically so again this is a quick introduction try to keep an eye on the keyboard so you can free yourself from mouse and always use your keys it's gonna give you a good advantage and it's gonna speed up your development process
Info
Channel: rmotr.com
Views: 63,895
Rating: 4.7761412 out of 5
Keywords: python, jupyter, data science, jupyterlab
Id: 7wfPqAyYADY
Channel Id: undefined
Length: 21min 42sec (1302 seconds)
Published: Fri Mar 29 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.