1 00:00:00,000 --> 00:00:03,448 Good, we were able to create a line 2 00:00:03,449 --> 00:00:06,689 graph using this code. And I hope you 3 00:00:06,689 --> 00:00:08,280 played around with this code a little bit, 4 00:00:08,773 --> 00:00:11,579 and got familiar with it. Now, you 5 00:00:11,579 --> 00:00:14,459 see here that we got two lists as 6 00:00:14,489 --> 00:00:17,159 output. In this lecture, I'll teach 7 00:00:17,159 --> 00:00:20,399 you how to use CSV files to feed your 8 00:00:20,399 --> 00:00:23,009 Bokeh graphs. And I'll use this code as 9 00:00:23,009 --> 00:00:25,169 a reference. So I'm just going to, you 10 00:00:25,169 --> 00:00:29,459 know, you need to press Escape. And when 11 00:00:29,459 --> 00:00:31,019 you press Escape, you can apply 12 00:00:31,019 --> 00:00:33,869 shortcuts, Keyboard Shortcuts to your 13 00:00:33,869 --> 00:00:36,329 cells. And you can see a list of 14 00:00:36,359 --> 00:00:38,549 shortcuts, in here, Keyboard Shotcuts. 15 00:00:39,239 --> 00:00:41,519 And for instance, what I want to do now 16 00:00:41,549 --> 00:00:44,189 is, I want to copy a cell with C and 17 00:00:44,189 --> 00:00:46,259 then I want to paste it this, I want to paste that 18 00:00:46,259 --> 00:00:49,139 cell below, with V. But first of all, 19 00:00:49,139 --> 00:00:52,979 you need to be in Command Mode. So to go 20 00:00:52,979 --> 00:00:55,079 into Command Mode, you need to press 21 00:00:55,079 --> 00:00:59,309 Escape as the help script says. And 22 00:00:59,309 --> 00:01:01,859 yeah, make sure Escape and then C, and 23 00:01:01,859 --> 00:01:04,049 then V, and you get another cell in 24 00:01:04,049 --> 00:01:07,979 here. Also, I'd like to actually remove 25 00:01:07,979 --> 00:01:11,849 for this header here, go to View, Toggle 26 00:01:11,849 --> 00:01:15,539 Header, Toggle Toolbars, so that I have 27 00:01:15,539 --> 00:01:18,179 more space for you here. So this is the 28 00:01:18,599 --> 00:01:21,509 code I'll be working with, Enter and 29 00:01:21,601 --> 00:01:23,879 yep, I'll be working in this code for now. 30 00:01:25,319 --> 00:01:29,519 And let me go here, this is working 31 00:01:29,519 --> 00:01:32,879 directory. I'll just go ahead and create 32 00:01:32,969 --> 00:01:38,383 a CSV file. Let's say data.csv 33 00:01:38,985 --> 00:01:43,409 Yes, and I'm just going to edit it with 34 00:01:43,769 --> 00:01:46,029 Notepad. So you can use Excel if you like. 35 00:01:46,030 --> 00:01:48,793 [No audio] 36 00:01:48,795 --> 00:01:51,329 So I just have two columns here, 37 00:01:51,599 --> 00:01:54,359 this, that is the header, and then 1 38 00:01:54,929 --> 00:01:59,879 for x, 6 for y, 2 and 7, and 39 00:01:59,909 --> 00:02:04,619 3 and 8, and 4 and 9, 40 00:02:05,669 --> 00:02:11,819 and one more 10. Save that. Close it. So note 41 00:02:11,819 --> 00:02:15,059 that data.csv is in a same directory 42 00:02:15,059 --> 00:02:20,099 with Basic graph.ipynb and go to 43 00:02:20,099 --> 00:02:23,369 your script. Now, we are importing 44 00:02:23,369 --> 00:02:25,109 Bokeh here, but I'll be importing 45 00:02:25,109 --> 00:02:27,149 pandas as well. So let's makes sure these are there 46 00:02:27,689 --> 00:02:32,489 and pandas. Let me use a lowercase b. 47 00:02:34,349 --> 00:02:38,249 import pandas. Yep, prepare some data. 48 00:02:38,250 --> 00:02:40,557 [No audio] 49 00:02:40,559 --> 00:02:46,679 So as you know pandas. So basically, 50 00:02:46,829 --> 00:02:48,719 the dataframe is the main object, and 51 00:02:48,719 --> 00:02:53,327 you want to create a dataframe from a CSV file. 52 00:02:55,280 --> 00:02:59,339 Now which is data.csv, just 53 00:02:59,339 --> 00:03:02,789 like that, and that. Now let's create two 54 00:03:02,789 --> 00:03:08,043 variables here. So the x variable will be equal to df 55 00:03:08,044 --> 00:03:10,107 [No audio] 56 00:03:10,109 --> 00:03:12,929 square brackets, the x column. 57 00:03:12,931 --> 00:03:15,453 [No audio] 58 00:03:15,454 --> 00:03:18,475 So don't confuse the x column with the x variable, 59 00:03:18,729 --> 00:03:20,937 and they just happen to have the same name. 60 00:03:21,686 --> 00:03:26,436 Okay. And also the y array, df 61 00:03:28,252 --> 00:03:32,754 y, okay. I know, that should do it. 62 00:03:34,030 --> 00:03:39,554 Let me rename this from_csv. 63 00:03:40,545 --> 00:03:43,679 Execute. And you get exactly 64 00:03:43,679 --> 00:03:48,119 the same line as we did earlier with 65 00:03:48,869 --> 00:03:51,869 plain array lists in here. And yeah, that's 66 00:03:51,869 --> 00:03:54,569 basically how you feed your Bokeh 67 00:03:54,569 --> 00:03:58,619 plots with pandas dataframe arrays. So 68 00:03:58,619 --> 00:04:03,449 again, just for the sake of clarifying 69 00:04:03,449 --> 00:04:06,059 things, this is the dataframe, and it 70 00:04:06,059 --> 00:04:09,959 has two columns. And you have the x 71 00:04:09,959 --> 00:04:13,109 column there. So that was stored. 72 00:04:13,259 --> 00:04:15,179 Actually, this is the index column, this 73 00:04:15,179 --> 00:04:17,489 one here. This is the actual data of 74 00:04:17,489 --> 00:04:20,589 that column and you also have the y column there. 75 00:04:20,590 --> 00:04:22,590 [No audio] 76 00:04:22,597 --> 00:04:25,979 So that's it. As you see a 77 00:04:26,219 --> 00:04:29,219 Bokeh is able to read plain lists, so 78 00:04:29,219 --> 00:04:30,779 Python list as this one here, 79 00:04:31,229 --> 00:04:34,349 actually, and also Panda dataframe 80 00:04:34,377 --> 00:04:37,287 array series. So this is called a 81 00:04:37,289 --> 00:04:42,304 series. You can check that yeah, a series. 82 00:04:43,648 --> 00:04:47,617 And here that's it. DD to delete a cell. And 83 00:04:48,299 --> 00:04:49,889 yeah, we'll move on with some more 84 00:04:49,889 --> 00:04:51,089 lectures there. See you. 85 00:04:51,090 --> 00:04:52,139 [No audio]