1 00:00:00,000 --> 00:00:10,215 Hey, in this video 2 00:00:10,215 --> 00:00:13,125 I'm going to share with you the Jupyter Notebook. 3 00:00:13,125 --> 00:00:15,600 The Jupyter notebook is a great way to get started 4 00:00:15,600 --> 00:00:18,300 with Python on the Coursera platform. 5 00:00:18,300 --> 00:00:20,520 It's a great way to do data science and other 6 00:00:20,520 --> 00:00:24,420 more advanced Python aspects on the platform too. 7 00:00:24,420 --> 00:00:27,010 So let's dive in and take a look. 8 00:00:27,080 --> 00:00:30,030 So when you log into the Jupyter platform 9 00:00:30,030 --> 00:00:32,550 you'll be greeted with a screen that looks like this. 10 00:00:32,550 --> 00:00:36,030 Jupyter is really built around this notion of code cells. 11 00:00:36,030 --> 00:00:37,860 So here I have one cell. 12 00:00:37,860 --> 00:00:39,950 Now there's a full Python interpreter 13 00:00:39,950 --> 00:00:41,885 running in the background behind this. 14 00:00:41,885 --> 00:00:44,285 So I can do things like create variables. 15 00:00:44,285 --> 00:00:46,940 So here I'll just say x equals 10. 16 00:00:46,940 --> 00:00:49,175 Then we'll just print x. 17 00:00:49,175 --> 00:00:51,290 You see there is no output until 18 00:00:51,290 --> 00:00:53,405 you actually go to run the cell. 19 00:00:53,405 --> 00:00:54,920 But when you run the cell 20 00:00:54,920 --> 00:00:57,110 the interpreter returns you the result. 21 00:00:57,110 --> 00:00:58,520 You also get a little number 22 00:00:58,520 --> 00:01:00,635 indicating how many cells have been run. 23 00:01:00,635 --> 00:01:02,690 So you can see in this example I played 24 00:01:02,690 --> 00:01:06,500 10 practice cells before actually showing this. 25 00:01:06,500 --> 00:01:08,600 Now after it runs, 26 00:01:08,600 --> 00:01:11,000 it's not like the application is finished running. 27 00:01:11,000 --> 00:01:13,580 The kernel is still running in an interpreter mode 28 00:01:13,580 --> 00:01:16,445 and we can continue to send queries to it. 29 00:01:16,445 --> 00:01:20,090 So if we wanted to say x plus x, 30 00:01:20,090 --> 00:01:23,220 and we wanted to print that, 31 00:01:27,020 --> 00:01:31,210 you can see that prints out as we expected. 32 00:01:31,210 --> 00:01:34,505 If you wanted to, you can stop the interpreter. 33 00:01:34,505 --> 00:01:36,980 So if you feel that the state is 34 00:01:36,980 --> 00:01:40,850 confusing or you just want a fresh Python instance. 35 00:01:40,850 --> 00:01:42,995 It's actually pretty easy to do that. 36 00:01:42,995 --> 00:01:45,890 You go to kernel and you say restart. 37 00:01:45,890 --> 00:01:49,085 Often I use restart and clear output as a way that 38 00:01:49,085 --> 00:01:51,830 reminds me that the interpreter 39 00:01:51,830 --> 00:01:54,185 is actually been restarted. 40 00:01:54,185 --> 00:01:58,400 You can cut, copy and paste cells and move them around. 41 00:01:58,400 --> 00:02:01,750 So you could do those normal kinds of things. 42 00:02:01,750 --> 00:02:05,010 The Jupyter notebook has a special feature, 43 00:02:05,010 --> 00:02:06,330 it actually has a number of them. 44 00:02:06,330 --> 00:02:08,330 But one is that if the result of 45 00:02:08,330 --> 00:02:10,480 your last statement was an object. 46 00:02:10,480 --> 00:02:11,930 There were some value returned 47 00:02:11,930 --> 00:02:13,660 but you don't do anything with that, 48 00:02:13,660 --> 00:02:17,375 it then automatically tries to print that to screen. 49 00:02:17,375 --> 00:02:19,115 Good example might be this. 50 00:02:19,115 --> 00:02:23,360 So if we say x equals 10 and then just the value x. 51 00:02:23,360 --> 00:02:25,850 Then we actually run that. 52 00:02:25,850 --> 00:02:27,560 We'll actually see the output. 53 00:02:27,560 --> 00:02:29,330 So you'll often see in some of 54 00:02:29,330 --> 00:02:33,650 the videos people just leaving the value towards the end. 55 00:02:33,650 --> 00:02:36,560 You can individually run cells. 56 00:02:36,560 --> 00:02:40,955 So for i in range 10. 57 00:02:40,955 --> 00:02:46,300 So if we want to have a loop print i. 58 00:02:46,300 --> 00:02:49,260 We could actually just not run this yet. 59 00:02:49,260 --> 00:02:50,620 We can say down here, 60 00:02:50,620 --> 00:02:53,360 wait what was the value of i and just run that 61 00:02:53,360 --> 00:02:57,005 individual cell and i is not actually defined. 62 00:02:57,005 --> 00:02:59,030 If we then decide we want to run that. 63 00:02:59,030 --> 00:03:00,680 Okay, there's a bunch of i's. 64 00:03:00,680 --> 00:03:02,765 Now run this cell again. 65 00:03:02,765 --> 00:03:04,400 We could do that. 66 00:03:04,400 --> 00:03:06,440 So you can see that we can have 67 00:03:06,440 --> 00:03:08,560 a non-linear editing format. 68 00:03:08,560 --> 00:03:11,165 That can be a little tricky actually because you can do 69 00:03:11,165 --> 00:03:14,510 things like change the value in one cell. 70 00:03:14,510 --> 00:03:16,265 But then you know this seems to 71 00:03:16,265 --> 00:03:18,980 suggest that i should be nine, 72 00:03:18,980 --> 00:03:20,420 but then when we run it we 73 00:03:20,420 --> 00:03:22,595 actually see that it's minus one. 74 00:03:22,595 --> 00:03:27,820 So you can sometimes get this irregular state, 75 00:03:27,820 --> 00:03:29,810 or at least it feels irregular. 76 00:03:29,810 --> 00:03:32,645 It's actually the interpreter, 77 00:03:32,645 --> 00:03:35,000 the way that you've run the cells 78 00:03:35,000 --> 00:03:37,580 in order determines the interpreter state. 79 00:03:37,580 --> 00:03:41,090 You can often see that if you look at the cell number 80 00:03:41,090 --> 00:03:42,770 here so six is greater than 81 00:03:42,770 --> 00:03:45,185 five but it's greater than three. 82 00:03:45,185 --> 00:03:46,520 So you can see that we're running 83 00:03:46,520 --> 00:03:49,450 some things in a different order. 84 00:03:49,450 --> 00:03:51,525 One of the benefits of 85 00:03:51,525 --> 00:03:53,210 the Jupyter platform is that you can 86 00:03:53,210 --> 00:03:55,460 adjust text in here as well. 87 00:03:55,460 --> 00:03:57,890 So let's say I want to describe. 88 00:03:57,890 --> 00:04:02,930 This is a great example of a loop. 89 00:04:02,930 --> 00:04:08,250 Let's say I want this section to even be called loops. 90 00:04:08,810 --> 00:04:12,320 So you can change the format of the cell here, 91 00:04:12,320 --> 00:04:14,170 and there's a number of different formats. 92 00:04:14,170 --> 00:04:15,905 You'll mostly use code 93 00:04:15,905 --> 00:04:18,155 and then something called markdown. 94 00:04:18,155 --> 00:04:21,185 So when you change it to markdown you'll note that the in 95 00:04:21,185 --> 00:04:22,910 out goes away because 96 00:04:22,910 --> 00:04:24,785 it won't be sent to the interpreter. 97 00:04:24,785 --> 00:04:26,480 But when you run the cell it'll 98 00:04:26,480 --> 00:04:33,165 actually run it in a data format called markdown. 99 00:04:33,165 --> 00:04:35,855 So, like the pound sign here 100 00:04:35,855 --> 00:04:39,095 or a double pound sign means give me a title. 101 00:04:39,095 --> 00:04:42,950 So when you actually run that you get a nice bit of text. 102 00:04:42,950 --> 00:04:46,580 So you can actually mark up your code execution 103 00:04:46,580 --> 00:04:50,705 in a way that's a lot like a textbook might be. 104 00:04:50,705 --> 00:04:54,530 You could create a whole textbook in this environment. 105 00:04:54,530 --> 00:04:59,075 So those are the main features of the Jupyter notebook. 106 00:04:59,075 --> 00:05:01,190 There are a bunch of other options. 107 00:05:01,190 --> 00:05:04,820 So one that I often use is- we'll restart and run all. 108 00:05:04,820 --> 00:05:07,640 So if I want to run all of the values in 109 00:05:07,640 --> 00:05:10,745 a notebook I want to just see the whole execution trace. 110 00:05:10,745 --> 00:05:12,650 You can do that. So in this case it 111 00:05:12,650 --> 00:05:15,045 would- will do that here. 112 00:05:15,045 --> 00:05:17,240 You'll see that it ran through the loop and then I 113 00:05:17,240 --> 00:05:19,655 print it out i and it's set up our markdown. 114 00:05:19,655 --> 00:05:21,725 That's a pretty common method. 115 00:05:21,725 --> 00:05:24,845 If it runs into an error it will pause execution. 116 00:05:24,845 --> 00:05:26,125 So that's important, because 117 00:05:26,125 --> 00:05:28,010 sometimes in a lecture video you might see we 118 00:05:28,010 --> 00:05:29,540 intentionally put an error in 119 00:05:29,540 --> 00:05:32,080 there for a teachable moment. 120 00:05:32,080 --> 00:05:34,985 Under the view there is some options as well. 121 00:05:34,985 --> 00:05:37,400 Line numbers is one that I will often turn 122 00:05:37,400 --> 00:05:40,885 on and that will number our cells as well. 123 00:05:40,885 --> 00:05:43,385 Each Jupyter notebook has 124 00:05:43,385 --> 00:05:47,030 a title for it and this determines the filename. 125 00:05:47,030 --> 00:05:49,860 So I'll just call this Demo. 126 00:05:49,910 --> 00:05:52,580 If you click on the Jupyter logo you'll 127 00:05:52,580 --> 00:05:54,395 be taken to what's called the Tree interface 128 00:05:54,395 --> 00:05:56,870 which is just a directory interface of 129 00:05:56,870 --> 00:05:59,825 the files that you have for this project. 130 00:05:59,825 --> 00:06:02,465 Within a given course on Coursera 131 00:06:02,465 --> 00:06:05,210 or a specialization or a degree on 132 00:06:05,210 --> 00:06:07,520 Coursera you may have any number of 133 00:06:07,520 --> 00:06:09,860 different Jupyter systems with 134 00:06:09,860 --> 00:06:13,675 different files spaces mounted on them. 135 00:06:13,675 --> 00:06:16,010 I also really like to be able to 136 00:06:16,010 --> 00:06:18,110 download my Jupyter Notebooks. 137 00:06:18,110 --> 00:06:20,794 So sometimes I download them as HTML, 138 00:06:20,794 --> 00:06:24,410 to show them to people or as a PDF version. 139 00:06:24,410 --> 00:06:27,550 So that can be quite helpful as well. 140 00:06:27,550 --> 00:06:30,980 So that's a quick tour of the Jupyter notebook. 141 00:06:30,980 --> 00:06:33,470 Now most of the work you'll be doing in this course, 142 00:06:33,470 --> 00:06:35,735 this specialization, or this degree 143 00:06:35,735 --> 00:06:37,850 will be in the Jupyter notebook. 144 00:06:37,850 --> 00:06:39,830 It's a great environment for doing 145 00:06:39,830 --> 00:06:41,885 Python and there's ways to create 146 00:06:41,885 --> 00:06:43,850 assignments and submit assignments 147 00:06:43,850 --> 00:06:46,970 directly to auto-graders from within the platform. 148 00:06:46,970 --> 00:06:49,130 I hope that we'll be able to share some of 149 00:06:49,130 --> 00:06:52,505 our research tools as well on educational technology. 150 00:06:52,505 --> 00:06:54,580 They are built into the Jupyter notebook. 151 00:06:54,580 --> 00:06:55,875 But we'll see how that goes. 152 00:06:55,875 --> 00:06:58,340 All right. We'll see you in the course.