Jupyter Notebook Complete Beginner Guide 2023 - From Jupyter to Jupyterlab, Google Colab and Kaggle!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey youtube my name is rob i'm a data scientist and i make videos about machine learning coding in python and all things data science in today's video we're going to be talking about jupiter notebooks or jupiter lab jupiter notebooks are essential tool for any data scientist coding in python so in this video we're going to talk about how to use jupyter notebooks on your local machine also some cloud environments that provide jupyter notebooks and then finally i'm going to show you some of the keyboard commands and shortcuts that i use every day and it really speeds up my workflow when working in jupiter notebooks so with that let's get started okay so before we actually get into jupiter notebooks we need to appreciate why they're helpful and before we do that i want to show you something in the terminal so you may already know this but if you're coding in python you actually can type in python into any terminal on your computer i'm running linux here but if you're on a mac or in powershell on a windows machine if you have python installed and type in python in the terminal you'll be taken into the python shell now this is where all the magic happens you can print hello viewers and it'll print you can add numbers five plus five and it adds it's python but the shell isn't a great way to actually do anything more than type in one line of code line by line of course so we can exit out of this and i can show you how you would write a script a script is just a file that you would um run python on so let's edit i have this test script that i've created all it has in it is print hello viewers and i can even show you here this is just in the a text editor on terminal but you can see here this is just a file that says hello viewers in the the file and if i run python on this test script it'll say hello viewers so this is great because you can run longer scripts that you've written and they can get more complicated you could add in modules and import things and they can get more and more fancy but we're here to talk about jupiter notebooks why jupiter notebooks helpful or important well before learning about jupiter notebooks we need to learn about one more thing and that's ipython that's what jupiter notebooks in jupiter lab is built off of ipython is similar to python but it has a little bit more functionality so if we type in print hello [Music] viewers again you can see that it's already colored it um we'll do a little bit of auto completing here so if i do hello viewers i can also do import pan if i do that and hit tab i can see the pandas autos completes as pd and then pd read csv if i do that i can actually see the files in this folder and some other autocomplete by hitting tabs so this is really handy about ipod then it was developed as an extension onto python to make it more interactive and jupyter notebooks were built off of that and we're going to show you now how to get into jupiter notebooks now one thing to keep in mind if you don't have jupyter notebooks on your local machine you can just pip install jupiter jupiter lab jupiter lab is the latest version of jupiter notebooks and it will install it for you i actually already have it installed so it's not that um exciting okay so after you have jupyter notebooks installed you'll be able to run it by just typing in jupyter notebook and what does this do well it's going to open immediately another window but one thing i want you to notice here is it started a jupiter server here on your local machine it's on a port 888 that's the default port all you really need to know is that something's running on your computer and now you can access it with your web browser so if we uh it'll either automatically open it up or if you click on this link it will open up your web browser and if you notice here the website localhost on port 8888 that's where jupiter notebook is being hosted on my machine and in jupiter notebooks you can actually now see the files in this folder i have my test script that i showed you before so this says hello viewers and then i also have can open that up i can edit it i could comment this out it's a simple text editor but you can also edit jupyter notebook files those will have the extension i p y and b when it loads up it looks like this and it's an environment where you can save your file uh copy things but the main thing that we're going to focus on is the fact that jupiter notebooks are all based around these cells and you can add cells by hitting this plus button or you can cut them or remove them with the little scissors you can copy a cell and you can paste the copy but the cell types are of cells are in two main types you have a markdown type this is uh basically plain text that you're going to want to write and have alongside your code so let's just type in here and this is markdown so if i do a hashtag i can make a title and i'm going to say example sorry jupiter notebook example and below this i can write a subtitle and with two hashtags i can write some text this is an example notebook and we can do things like uh lists lit this is item one next is two and then three so you can do more than just writing plain text here you actually write notebook uh sorry markdown and this will be right next to your code cells so code cell is where now we can actually write python and it hasn't launched yet but as soon as i uh write hello viewers and run this cell you can see there is now a one by the hello viewer cell and we are now running a actual python kernel environment in the background so we know that we can write plain text have it right next to our actual code that we've run but the other great thing is that we can write code that exports something like an image or a graphic and it'll show it in the notebook and render it so let's import numpy and let's import matplotlib and show a plotting example so this is just an example from the plotting uh matplotlib website and we're gonna plot some example uh data here and this is great so we could plot show the result we have our code up here and then we can also now write some text so we can make a markdown cell right below it uh this plot above is amazing we've learned 50 things and then you can go on to list all your things and this notebook file you can now share with people and they can see your thought process and your code run all the way from the start to the end and that's really the power be behind jupiter notebooks but we're going to take it up a notch and we're going to look at jupiter lab which is the latest version of jupiter notebooks and add some additional functionality so i'm going to go back to my terminal and i'm going to hit ctrl c to shut this down this notebook down that we've been running in the background and instead of typing jupiter notebook i'm going to type in jupiter lab and what comes up here but a different looking environment now one thing i'll mention here is that this theme i have as the dark theme by default but when you load it up it'll probably look something like this and now we have this tab here on the left side that is a little bit more of an advanced way of allowing us to browse through our files that we have so we still have our test script here and we have our example notebook that we're working on before and we can see that we have still our text markdown cells and our code cells but we have a little bit a little bit easier way of navigating around with this navigation or file browser tab we also have this running tab this allows us to see all the notebooks and the tabs we have open and all the kernels that are running or or uh python instances that are actually running so not only do i have this notebook open but we have a python environment running in the background that's allowing this code to run if i hit shutdown on all it'll shut down this kernel in the background and now when i run the first cell of code here it will have to start up a brand new kernel and you can see it pop up here again so now if i run print hello viewers it prints it out it shows the number one by it to show that cell was run first and then we can run our other code now some things i want to mention here is the order in which you run your cells in the um jupiter notebook or jupiter lab will actually does not have to be from top to bottom like in normal coding so this can get confusing at first and it means that you can experiment more by going back and forth between cells it's one of the real powerful things about jupiter lab in jupiter notebooks but it also allows for some bad practices where um you can make a notebook that doesn't actually run end to end and it's important to go through once you're saving off your notebook and to make sure it actually can run all the way from the top to the bottom or else you're really going to confuse yourself later like let's say i restart this kernel we're going to hide this and i'm going to put it in this order so i'm going to run hello viewers i'm going to do my imports here and then i'm going to do my plot third here if i try to reset this and run this um run this from top to bottom i'm going to try to print hello viewers try to do my plotting but i haven't imported numpy yet so it's going to give me an error it worked before because i ran it out of order but it's important to keep it in order when you're actually um creating your your final notebooks um some other things to kee to keep in mind about jupiter lab is you have this tab that shows your table of contents so remember we added a title here and a subtitle this allows us to quickly jump around if we wanted to make this um discussion of plot here now we see it here in our in our table of contents that we can easily jump around we also have an extension tab so jupiter lab allows for a bunch of different extensions to be added what you could see before was i added this jupiter lab solarize dark theme which i really like which allows me to go to the settings theme jupiter labs solarize dark theme and i can actually have my code look in um in nice colors that i think is visually pleasing so there are a bunch of different extensions that you can add you can search for them or you um like this solarize theme i just found on this github page and i pip installed it in my environment all i had to do was pip install like this and that then it showed up as an extension that i've added um so a lot of things that you can do in jupiter lab that you can't necessarily do in jupiter notebooks and and it's really great for writing code that you then can save off now some things that i utilize a lot is when you want to save your notebook and your code if you're sending it someone who does not have jupyter you can export it as uh different file types you can export it as html which actually renders pretty nice if you emailed this to someone they would be able to see the text and the code and the plots all next to each other which is great you can also export it you can also export it as a pdf if you want to or other types but really html usually looks the prettiest in my opinion and it doesn't actually split up by pages which is a nice thing some other things to keep in mind you can want to save your notebook often to make sure you don't lose what you've been working on you can go to file save or click on save here if you want to test out your notebook running from end to end you can actually click on this run and restart kernel and run all cells will actually run it from the start to the end so you'll see that pop up and it'll show you run it from the start to the end and then you have some more settings that you can set in here like how you want your tabs to set up um your indentation uh key mapping it's all you can go into all the details of settings and really make jupyter lab work for you as best as you can so now i've showed you how to run jupyter notebooks and jupyter labs on your local machine but jupiter notebooks have become so popular that you can actually run them in cloud instances so there are a few different ways that you can run jupyter in the cloud and some of the most popular ones are google colab and kaggle notebooks first i'm going to show you google co-lab so if you go to colab.research.google.com and you have a google account you can create a notebook pretty simple the nice thing about running it in the cloud is you don't have to worry about installing python on your local machine installing all the packages you might need the environment's usually set up with a lot of data science packages already loaded so we're gonna go here to collab and create a new notebook and the environment looks a little bit different but there's a lot of similarities so we're gonna show call this example notebook we're going to make a markdown they call it texts here we're going to move this one up and say google collab notebook this works and we can print here hello viewers just like we did before and why don't i go here and actually do the same plot we did before in the notebook here this is all running in the cloud um in google collab you can see that the instance that you're given up here has certain amount of resources so this has uh over 12 gigs of ram on it it has some cpu usage that you can view here in the top right to see how much you're actually using of the instance as you're running your notebook um we can also i i believe we can we can download this ipi notebook file with the notebook file itself we can save it directly to github or copy it to drive so this is a a nice and easy way to get started with jupyter notebooks in the cloud using google colab now the last jupiter notebook type of environment i want to show you are called kaggle notebooks and kaggle is a free website that actually uses a lot of the same functionality of google collab and jupiter in the background in their notebooks so i if you have an account you can go to this code page and create a new notebook like i just did there and let's call this example notebook and very similar to google colab once we run it example kaggle notebook this is great print test test one two three so one of the really nice things about working in the kaggle environment is you actually have access to all the public data sets they provide which you can easily link to your notebook and load into to run analysis so if we go into here in this tab on to the right i can add data and there's a bunch of public data sets you can filter by the most votes or the newest ones uh let's just look at some of my data sets we're gonna add in this mr beast youtube stats data set that i've created and i'm gonna import pandas and it's always saved into the input directory but we're gonna run this and pull in the data data frame for stats i'm using pandas here if you want to learn more about pandas i do have a video on some basic introduction to using pandas but as you can see i've loaded in the data i can take his videos and i can plot um the view count on and plot by the like count of each video mr beast videos and here we have it we've created this plot here and we can add cells below with text analysis here the nice thing other nice thing about kaggle notebooks is it forces you to when you save it run all your code in order from start to end so although i may go around here and run back and forth exploration while i may here run cells out of order while i'm exploring the data when i actually go to save it it's going to run it from the top to the end and it'll show as failed if it doesn't render correctly but if it does render correctly you actually have a public version of your final notebook and we'll go here and show once it's done once it's done running end to end and it doesn't fail you can actually share this notebook publicly and anyone with the link can go and view it it's one of the great things about using a notebook as opposed to something on your local machine one of the last things i want to leave you with are some of the things that i do to really speed up my use of jupiter notebooks and that's by using keyboard commands that can really speed up your day-to-day workflow so the main things i want to talk about are just running cells so though the quickest way to run a cell as opposed to clicking on run the cell icon is to actually just do shift enter and by doing this i can run these cells very easily shift enter and then i can use the arrow keys to move around from cell to cell as i'm running them shift enter will actually take you to the next cell after you're done running it and sometimes that's what you want to do other times you'd want to run a cell and stay in that cell and you can do that just by hitting control enter so now i can run this cell as many times as i want and stay in that cell other really important commands are when you're working in a cell and you want to escape out into it and move to a different cell you just hit the escape key now i'm out of that cell and i can move around by using my j and k keys this lets you not have to take your fingers off of the keyboard when you're moving from cell to cell so i can move run this cell move up here edit this text ctrl enter to run that and then move around so these are command c shortcuts should become like second nature to you if you're working in jupiter notebooks a lot another command that i use all the time is to add and remove cells that you have existing so a so once you are escaped so once you have escaped out of the cell that you're working in you can quickly add a cell by typing a that'll add a cell above the cell you are currently on you can add a cell quickly below the cell that you're on by typing in b so a and b will just add cells above and below you can also quickly delete a cell that you're on by typing dd so if i'm on this cell above hello viewers dd will delete dd to delete this other cell escape out i can move up and down using j and k and finally the command that i use a lot that speeds things up is you can change between markdown and code types of cells by simply escaping out and typing m for markdown or y for code so you could see here i can easily above this import numpy do a to add a cell above it m to change it to markdown hit enter to enter the cell and then uh this is where i import control enter i've entered that cell in and continue on without taking my fingers off the keyboards once so that's my quick introduction to jupiter lab jupiter notebooks and cloud notebooks i hope it was helpful if there's any suggestions you have please add a comment below like and subscribe if you enjoyed this video and learn something from it and let me know what you'd like to see a video about next see you guys in the next video bye
Info
Channel: Rob Mulla
Views: 118,074
Rating: undefined out of 5
Keywords: ultimate jupyter notebook guide, jupyter notebook tutorial, jupyter notebook for beginners, jupyter notebook for python, data science for beginners, python notebook, python notebook jupyter, kaggle notebook tutorial, google colab, how to use jupyter notebook, how to use jupyter notebook for python, jupyterlab, jupyterlab tutorial, jupyterlab vs jupyter notebook, jupyter notebook for data analysis, rob mulla, 2022, jupiter notebook, jupiter notebook tutorial, jupyter lab
Id: 5pf0_bpNbkw
Channel Id: undefined
Length: 25min 11sec (1511 seconds)
Published: Sat Jan 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.