1 00:00:00,001 --> 00:00:02,165 Well, in this lecture, I'll show you how 2 00:00:02,190 --> 00:00:04,530 to set up the Jupyter Notebook, or 3 00:00:04,530 --> 00:00:07,230 Jupyter for short, and also how to use 4 00:00:07,230 --> 00:00:10,260 it. So far, you've worked both with a 5 00:00:10,260 --> 00:00:13,020 Python or an IPython Interactive Shell. 6 00:00:13,740 --> 00:00:16,110 But also you've worked with an editor, 7 00:00:16,135 --> 00:00:20,580 such as Atom. Sometimes, you may have the 8 00:00:20,580 --> 00:00:24,630 need for a hybrid between an interactive 9 00:00:24,630 --> 00:00:28,110 shell and an editor, when you want to 10 00:00:28,110 --> 00:00:30,750 test things out, but you also want to 11 00:00:30,750 --> 00:00:33,210 save your blocks of code that you're 12 00:00:33,210 --> 00:00:36,180 writing. Because an interactive shell is 13 00:00:36,180 --> 00:00:39,540 great for testing things quickly. But 14 00:00:39,540 --> 00:00:42,720 you can save the code, and the editor is 15 00:00:42,720 --> 00:00:44,610 good for saving the code, that is not 16 00:00:44,610 --> 00:00:47,820 great for testing things. But I can tell 17 00:00:47,845 --> 00:00:50,935 you that Soldier Hubert tool exists, 18 00:00:50,960 --> 00:00:53,730 and that is called Jupyter Notebook, and 19 00:00:53,730 --> 00:00:56,070 that is an amazing tool that will boost 20 00:00:56,070 --> 00:00:58,410 your productivity, and Jupyter is 21 00:00:58,410 --> 00:01:00,360 especially good when you're working with 22 00:01:00,390 --> 00:01:03,450 data, as it's a great environment to 23 00:01:03,450 --> 00:01:05,820 explore data, and you'll see its 24 00:01:05,820 --> 00:01:08,550 usefulness in just a bit. Of course, you 25 00:01:08,575 --> 00:01:11,005 still want to use editor, such as Atom, 26 00:01:11,405 --> 00:01:13,325 when you're working with multiple Python 27 00:01:13,350 --> 00:01:16,410 scripts that interact with each other. 28 00:01:17,645 --> 00:01:20,465 That's the case of web application. For 29 00:01:20,490 --> 00:01:22,140 example, when you're developing web 30 00:01:22,140 --> 00:01:24,090 applications, you'll have to deal with 31 00:01:24,120 --> 00:01:26,580 multiple Python scripts, and also HTML 32 00:01:26,580 --> 00:01:30,090 files, CSS, and other files as well. We'll 33 00:01:30,090 --> 00:01:32,310 build web application later in the course, 34 00:01:32,340 --> 00:01:34,170 and you'll see how Atom is good for 35 00:01:34,170 --> 00:01:38,880 that. But for data, use Jupyter, so 36 00:01:38,880 --> 00:01:41,220 Jupyter, let's see how to install it. 37 00:01:41,850 --> 00:01:44,790 Well, we can go to the installation, so 38 00:01:44,790 --> 00:01:48,180 install, and you can go through these 39 00:01:48,180 --> 00:01:50,670 instructions. But instead of going 40 00:01:50,670 --> 00:01:53,670 through this advice, you actually to use 41 00:01:53,670 --> 00:01:56,975 your command line to install Jupyter and type in 42 00:01:57,000 --> 00:02:00,718 pip install jupyter. 43 00:02:00,742 --> 00:02:03,713 [No audio] 44 00:02:03,738 --> 00:02:06,875 So that will download Jupyter and it will install it 45 00:02:06,900 --> 00:02:11,580 in your system, and then to start a 46 00:02:11,580 --> 00:02:13,650 Jupyter session, a good practice is to 47 00:02:13,650 --> 00:02:15,295 go to a folder, 48 00:02:15,319 --> 00:02:17,319 [No audio] 49 00:02:17,344 --> 00:02:19,353 let's say test3, 50 00:02:20,010 --> 00:02:23,013 and here you can open a command prompt, 51 00:02:23,037 --> 00:02:25,037 [No audio] 52 00:02:25,062 --> 00:02:29,321 and then you type jupyter notebook. 53 00:02:29,345 --> 00:02:32,333 [No audio] 54 00:02:32,358 --> 00:02:35,340 Now, that will open a Jupyter session in the browser. 55 00:02:35,550 --> 00:02:38,430 So the Jupyter Notebook is actually a 56 00:02:38,430 --> 00:02:40,830 browser notebook. The reason I opened 57 00:02:40,830 --> 00:02:43,110 the Jupyter notebook in the command line 58 00:02:43,385 --> 00:02:45,785 was that, at least on Windows when you 59 00:02:45,810 --> 00:02:47,730 do Shift, and then right click on a 60 00:02:47,730 --> 00:02:50,670 folder, your command prompt is opened in 61 00:02:50,695 --> 00:02:52,675 the current folder. So in this we are here, 62 00:02:53,130 --> 00:02:55,440 and then when you create a notebook 63 00:02:55,530 --> 00:02:58,320 file now, every file will be saved in 64 00:02:58,320 --> 00:03:01,650 this directory here. Alternatively, you 65 00:03:01,650 --> 00:03:03,840 can open your command prompt everywhere 66 00:03:03,840 --> 00:03:06,900 you want, and then you can cd to the 67 00:03:06,900 --> 00:03:09,420 folder where you want to save your 68 00:03:09,420 --> 00:03:11,760 Jupyter Notebooks. All right, now, 69 00:03:11,760 --> 00:03:13,980 we don't have anything here. So what 70 00:03:14,005 --> 00:03:17,725 you're going to do is Create a notebook. 71 00:03:18,390 --> 00:03:21,120 And we install Jupyter as Python 72 00:03:21,120 --> 00:03:23,340 libraries, so on the notebooks, we have 73 00:03:23,340 --> 00:03:26,790 Python 3 available. So the kernel 74 00:03:26,790 --> 00:03:30,540 will be Python 3. If you have 75 00:03:30,540 --> 00:03:32,459 associated other languages here, you'll 76 00:03:32,484 --> 00:03:34,290 see them under here on their 77 00:03:34,290 --> 00:03:37,500 notebooks. So this is an empty 78 00:03:37,525 --> 00:03:40,744 notebook, and this is the name of 79 00:03:40,769 --> 00:03:44,910 the Notebook, and you can change these to, let's 80 00:03:44,910 --> 00:03:50,040 say, Testing, press OK, and if you go to 81 00:03:50,040 --> 00:03:52,740 the folder, you'll see that file with 82 00:03:53,070 --> 00:03:56,640 Testing name and IPython Notebook 83 00:03:56,640 --> 00:03:59,370 extension was created. So that is 84 00:03:59,370 --> 00:04:01,320 created automatically every time you 85 00:04:01,320 --> 00:04:02,790 type something here, you do some 86 00:04:02,790 --> 00:04:04,980 changes or something. Now let me show 87 00:04:04,980 --> 00:04:06,930 you how you can work with IPython 88 00:04:06,930 --> 00:04:10,260 Notebook. So you can consider every cell, 89 00:04:10,290 --> 00:04:12,450 oh this is a cell, and you can consider every 90 00:04:12,450 --> 00:04:16,140 cell as a line in normal Python 91 00:04:16,140 --> 00:04:18,000 Shell. But here in this shell, you can 92 00:04:18,000 --> 00:04:21,360 actually write multiple lines of code, 93 00:04:21,630 --> 00:04:24,480 let's say print 1, and then if you 94 00:04:24,480 --> 00:04:26,190 don't want to execute it this right 95 00:04:26,190 --> 00:04:27,960 away, you can press Enter. So with 96 00:04:27,960 --> 00:04:29,790 Enter, you enter a new line in the cell, 97 00:04:29,940 --> 00:04:33,630 and then print 2, and so on, and if you 98 00:04:33,630 --> 00:04:36,480 want to execute the cell now, you can 99 00:04:36,510 --> 00:04:39,990 press Ctrl Enter, and you get the 100 00:04:39,990 --> 00:04:42,420 output. Now if you want to create a new 101 00:04:42,420 --> 00:04:47,250 cell, Alt Enter would do that, and here 102 00:04:47,250 --> 00:04:49,200 you can write another block of code. 103 00:04:49,224 --> 00:04:51,224 [No audio] 104 00:04:51,240 --> 00:04:54,630 With Enter, you go to the next line, and 105 00:04:54,630 --> 00:04:58,590 so on and if you want to go to the next 106 00:04:58,590 --> 00:05:01,860 cell right away, so before we pressed 107 00:05:01,925 --> 00:05:04,379 Ctrl Enter, now you can press Shift Enter 108 00:05:04,403 --> 00:05:05,670 and you go to the next cell 109 00:05:05,670 --> 00:05:07,710 automatically, and with Shift Enter, you 110 00:05:07,710 --> 00:05:10,530 can, you also execute the cell where you 111 00:05:10,530 --> 00:05:12,780 are working on, you can create new cells 112 00:05:12,780 --> 00:05:15,360 with Alt Enter, and you can deal with 113 00:05:15,385 --> 00:05:18,355 them by pressing first, you press Escape, 114 00:05:19,200 --> 00:05:21,810 and then you press DD two times, DD 115 00:05:21,810 --> 00:05:26,040 again, so it's quite flexible. Something 116 00:05:26,040 --> 00:05:27,810 you should notice is that we have two 117 00:05:27,810 --> 00:05:30,690 modes. Basically, we have the command 118 00:05:30,690 --> 00:05:32,670 mode. So when you are in the command 119 00:05:32,670 --> 00:05:36,090 mode, you see a gray rectangle around 120 00:05:36,090 --> 00:05:39,600 the cell, and when you are to go to the 121 00:05:39,600 --> 00:05:41,910 edit mode, then you press Enter. So 122 00:05:41,910 --> 00:05:43,800 while you are focused on the 123 00:05:43,800 --> 00:05:45,510 current cell, the press Enter, and then 124 00:05:45,510 --> 00:05:49,727 you edit the cell. So in edit mode, 125 00:05:49,752 --> 00:05:52,230 when you type things, you're 126 00:05:52,230 --> 00:05:53,910 inserting text in the cell, you're 127 00:05:53,935 --> 00:05:57,355 inserting code in the cell, Escape 128 00:05:57,545 --> 00:06:00,215 and command mode, DD and you delete the 129 00:06:00,240 --> 00:06:03,912 cell, Alt Enter, and you enter a new cell. 130 00:06:03,936 --> 00:06:06,161 [No audio] 131 00:06:06,186 --> 00:06:08,160 So these are the most used 132 00:06:08,160 --> 00:06:10,710 shortcuts, keyboard shortcuts. But if 133 00:06:10,710 --> 00:06:12,840 you want to know more shortcuts, you can 134 00:06:12,840 --> 00:06:15,990 go to Help, and then Keyboard Shortcuts, 135 00:06:16,020 --> 00:06:17,795 and then you see a list here. 136 00:06:17,819 --> 00:06:19,850 [No audio] 137 00:06:19,875 --> 00:06:23,370 But these are good to get started. When you're 138 00:06:23,370 --> 00:06:25,590 done with this, you can just close the 139 00:06:25,590 --> 00:06:27,960 tab, and you can also close the 140 00:06:27,960 --> 00:06:30,510 directory tree here. So notice that 141 00:06:30,547 --> 00:06:33,547 Jupyter actually opens in a localhost 142 00:06:33,750 --> 00:06:36,840 session, and if you want to open again 143 00:06:36,840 --> 00:06:40,170 your notebook, so you can go here again 144 00:06:40,195 --> 00:06:44,245 and go to Open command window here and 145 00:06:44,880 --> 00:06:46,955 jupyter notebook, 146 00:06:46,979 --> 00:06:49,788 [No audio] 147 00:06:49,813 --> 00:06:51,421 and here is the file, 148 00:06:53,050 --> 00:06:56,520 and is just as we left it. Now, a 149 00:06:56,520 --> 00:06:59,280 Jupyter Notebook is best to use for 150 00:06:59,580 --> 00:07:02,040 doing explorations, and especially, data 151 00:07:02,040 --> 00:07:04,260 explorations. So if you're working, 152 00:07:04,260 --> 00:07:06,690 let's say with data analysis or data 153 00:07:06,690 --> 00:07:09,420 visualizations, the Jupyter Notebook 154 00:07:09,420 --> 00:07:12,390 is perfect to use. You can use the 155 00:07:12,420 --> 00:07:15,360 Jupyter Notebook, for example, to load a 156 00:07:15,390 --> 00:07:18,960 table of data in the session. For that 157 00:07:18,960 --> 00:07:20,037 you'd use pandas. 158 00:07:20,062 --> 00:07:22,139 [No audio] 159 00:07:22,164 --> 00:07:25,740 So you import the library, you press Enter, or Shift Enter 160 00:07:25,740 --> 00:07:27,570 to go to the next cell, and you press 161 00:07:27,570 --> 00:07:30,270 Enter again to write something. So let's 162 00:07:30,295 --> 00:07:33,805 say df equals to pandas.read_csv. 163 00:07:33,829 --> 00:07:37,150 [No audio] 164 00:07:37,175 --> 00:07:41,610 And I have csv file somewhere in my system. 165 00:07:41,634 --> 00:07:46,895 [No audio] 166 00:07:46,920 --> 00:07:48,255 Press Enter and 167 00:07:48,279 --> 00:07:50,279 [No audio] 168 00:07:50,286 --> 00:07:53,550 Wow, so you get a nice HTML 169 00:07:53,550 --> 00:07:56,460 table which was loaded from the csv 170 00:07:56,460 --> 00:07:58,680 file, and you can also plot graphs in 171 00:07:58,680 --> 00:08:00,570 the Jupyter Notebook. So that's also 172 00:08:00,570 --> 00:08:02,820 something you're learning in the course. 173 00:08:03,360 --> 00:08:05,880 And so data analysis on visualizations, 174 00:08:06,210 --> 00:08:08,730 you can also use the Jupyter Notebook 175 00:08:08,760 --> 00:08:11,220 for web scrapping and that is very 176 00:08:11,258 --> 00:08:13,658 convenient, because you would have this 177 00:08:13,819 --> 00:08:16,350 blocks of code and then you have to 178 00:08:16,350 --> 00:08:19,650 continuously tweak the code. So you may 179 00:08:19,650 --> 00:08:21,960 want to change something here, then you 180 00:08:21,960 --> 00:08:25,140 get a nice display, not this one 181 00:08:25,140 --> 00:08:27,810 exactly because this is a messed up stream, 182 00:08:27,810 --> 00:08:30,450 but this one, for instance, you have a 183 00:08:30,450 --> 00:08:34,290 slider here so you can scroll up and 184 00:08:34,290 --> 00:08:37,740 down, you know, inside a separate window that 185 00:08:38,070 --> 00:08:40,860 doesn't affect your general, your main 186 00:08:40,860 --> 00:08:43,830 window. So I hope you have you've gotten 187 00:08:43,830 --> 00:08:46,260 a good idea of the Jupyter Notebook. 188 00:08:46,796 --> 00:08:48,626 Just take a note of the shortcuts, of the 189 00:08:48,660 --> 00:08:51,600 keyboard shortcuts to execute code the 190 00:08:51,600 --> 00:08:54,120 editor and the command mode, you know, 191 00:08:54,120 --> 00:08:56,190 Enter, Escape, and Enter again, and so 192 00:08:56,190 --> 00:08:59,220 on and so forth, and you just 193 00:08:59,220 --> 00:09:00,570 practice them a little bit and you'll 194 00:09:00,600 --> 00:09:02,910 get used to with Jupyter very 195 00:09:02,910 --> 00:09:05,813 quickly. See you in the next lecture.