You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-23Lines changed: 24 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,19 +3,19 @@
3
3
4
4
### Introduction
5
5
6
-
So far, many of the readings and all of the labs you have been working with have been interactive. You are working in an environment that allows us to both display text, and run Python code. In this lesson, we explore the software powering these interactive documents, Jupyter.
6
+
So far, many of the readings and all of the labs you have been working with have been interactive. You are working in an environment that allows us to both display text, and run Python code. In this lesson, we explore Jupyter, the software powering these interactive documents.
7
7
8
8
### Jupyter Background
9
9
10
10
Jupyter is a web application that allows someone to create and work with documents that have live code. It's a very popular tool among data scientists, as it allows for both explanation of thinking behind code as well as the code itself.
11
11
12
12
### Introduction to cells
13
13
14
-
The notebook itself consists of cells. Double click on this content and to see what I mean. Once we double click on a cell, we are in insert mode. This means that we are able to edit the cells, just as you would if this were a word document. We can tell that we are in insert mode because of the green border around the cell.
14
+
The notebook itself consists of cells. Double click on this content to see what I mean. Once we double click on a cell, we are in insert mode. This means that we are able to edit the cells, just as you would if this were a word document. We can tell that we are in insert mode because of the green border around the cell.
15
15
16
-
Now, after being in insert mode for this cell, change some of the content. Write anything, we can always undo it. We can undo the changes of a cell by making sure we are in insert mode and then pressing command+z on a mac or control+z on windows.
16
+
After entering insert mode for this cell, change some content. Don't worry about what you change as we can always undo it. We can revert our changes to a cell by making sure that we are still in insert mode and by pressing `command + z` on a mac or `control + z` on windows.
17
17
18
-
To get out of insert mode and write the current changes and see the effect of the current changes, press shift + enter.
18
+
To get out of insert mode and see the effect of our changes, press `shift + enter`.
19
19
20
20
### Adding and Deleting Cells
21
21
@@ -26,43 +26,44 @@ We have already seen, to alter the contents of a cell we simply double click on
26
26
If we wish to quickly add a new cell we can do so with the following steps:
27
27
28
28
* Make sure we are not in insert mode, but in escape mode
29
-
* To get into escape mode, press the escape key. You will no longer see a cell bordered in green.
30
-
* Then press the letter "b"
31
-
* Once in escape mode, press the letter b
29
+
**Remember we can tell we are in insert mode when we have a green border around our cell.*
30
+
* To get out of insert mode and into escape mode, press the escape key.
31
+
* You will no longer see a cell bordered in green.
32
+
* Then press the letter `b`
32
33
33
34
#### Deleting cells
34
35
35
-
To delete a cell we once again should be in escape mode, and then press the "x" key.
36
+
To delete a cell we once again should be in escape mode, and then press the `x` key.
36
37
37
-
Of course, we'll want a way to undo our deletion. You can press d to undo deletion of a cell. Notice that this is different from cmd+z. Pressing cmd+z undoes our changes inside of a cell, but pressing d from escape mode is to undo changing a cell in it's entirety.
38
+
Of course, we'll want a way to undo our deletion. You can press d to undo deletion of a cell. Note that this is different from `cmd + z`. Pressing `cmd + z` undoes our changes inside of a cell, but pressing `d` from escape mode is to undo changing a cell in it's entirety.
38
39
39
40
### Types of Cells
40
41
41
42
The current cell and every other cell in this lesson has been a markdown cell, meaning that it allows us to write text and stylize that text. For example, if you surround some text with stars on either side the text **becomes bold**. That's markdown.
42
43
43
-
Cells can also have a type of Python code. If we are writing in a cell that is for Python, everything in that cell must be valid Python or we will see an error.
44
+
Cells can also have a type of code. If we are writing in a cell that is for Python code, everything in that cell must be valid Python or we will see an error.
44
45
45
46
46
47
```python
47
48
This is a python cell without valid Python so we wil see an error
48
49
```
49
50
50
-
So a cell must either be of type Python, in which case all of the contents must be valid Python, or a cell must be of type markdown. It cannot be both. We can quickly change a cell from markdown to code with some keyboard shortcuts.
51
+
So, a cell must either be of type markdown or of type code, in which case all of the contents must be valid Python. It cannot be both. We can quickly change a cell from markdown to code with some keyboard shortcuts.
51
52
52
-
From escape mode, we change a cell to type code by pressing the letter y. Add a new cell by pressing the letter b, then type j to change that cell into type code. Again, press shift + enter to save the changes of the cell. To change the cell from code to markdown, from escape mode press the letter m.
53
+
From escape mode, we change a cell to type code by pressing the letter `y`. Add a new cell by pressing the letter `b`, then type `j` to change that cell into type code. Again, press `shift + enter` to save the changes of the cell. From escape mode, press the letter `m`to change the cell from code to markdown.
53
54
54
55
### Working with Python in Jupyter
55
56
56
-
Ok, now that we know a little bit about adding and deleting cells, as well as changing cell types from markdown to Python, let's focus on working with Python in Jupyter. We'll go into a large amount of detail about working with a Jupyter notebook in Python, but the main takeaway is this: if we see a Python cell, we should press shift + enter on that cell.
57
+
Ok, now that we know a little bit about adding and deleting cells, as well as changing cell types from markdown to code, let's focus on working with Python in Jupyter. We'll go into a large amount of detail about working with a Jupyter notebook in Python, but the main takeaway is this: if we see a Python cell, we should press `shift + enter` on that cell.
57
58
58
-
The major gotcha in with working with Python code is that Python will only execute the Python cells that are run. So for example, just seeing the cell where we define `name` to `'bob'` below does not write that cell to memory.
59
+
The major gotcha in working with Python code is that Python will only execute the cells that are run. So for example, just seeing the cell where we define `name` to `'bob'` below does not write that cell to memory.
59
60
60
61
61
62
```python
62
63
name ='bob'
63
64
```
64
65
65
-
If we try to reference that variable later on, Python will tell us that it is not defined.
66
+
If we try to reference that variable later on withouth having run it, Python will tell us that it is not defined.
66
67
67
68
68
69
```python
@@ -81,7 +82,7 @@ name
81
82
NameError: name 'name' is not defined
82
83
83
84
84
-
To execute or run a cell, we must press shift + enter from escape mode on that cell. Upon running a show, Python will show the the last line of the cell's return value underneath. Let's see this.
85
+
To execute or run a cell, we must press `shift + enter` from escape mode on that cell. Upon running a cell, Python will show the the last line of the cell's return value underneath. Let's run the cell below to see this:
85
86
86
87
87
88
```python
@@ -96,9 +97,9 @@ age
96
97
97
98
98
99
99
-
As you can the variable `age` is set to 14, so when the cell is run `14` is displayed underneath.
100
+
As you can see the variable `age` is set to 14, so when the cell is run `14` is displayed underneath.
100
101
101
-
One tricky thing to note is that assigning a varible **does not** have a return a value. So even though the cell is run, if assigning a variable is the last line of a cell, nothing is displayed underneath.
102
+
One tricky thing to note is that assignment, the action of assigning a varible,**does not** have a return a value. So, even though the cell is run, if the last line of cell is the assigning of a variable, nothing is displayed underneath.
102
103
103
104
104
105
```python
@@ -119,7 +120,7 @@ hometown
119
120
120
121
121
122
122
-
> Yes, it's pretty confusing, but all we need to know is that just because we don't see something below a cell after pressing shift + enter, does not mean it is not run. In the case of assignment, it is because the return value of assignment in None, and `None`does not show an output.
123
+
> Yes, it's pretty confusing, but the important thing to take away is that we need to run our cells with Python code by pressing `shift + enter` if we want Python to read our variables and functions and remember them later on. Remember, in the case of assignment, the return value is `None`, which does not show an output. We can see this more concretely below by running the cell below:
123
124
124
125
125
126
```python
@@ -128,12 +129,12 @@ None
128
129
129
130
### Working through labs and readmes
130
131
131
-
As you read through labs we encourage you to press shift + enter on each of the Python cells. Often in labs, we will assign variables to data early on. Then we will ask you to work with data stored in those variables. To avoid going to the top of the lab to press shift + enter, it's best just to press that while reading along.
132
+
As you read through labs we encourage you to press shift + enter on each of the Python cells. Often in labs, we will assign variables to data early on. Then we will ask you to work with data stored in those variables. To avoid going to the top of the lab to press `shift + enter`, it's best just to press that while reading along.
132
133
133
-
The same thing goes for working through a Readme. The Readmes will often assign data to variables, and it may be nice to work with data stored in those variables later on. So it's a good idea to press shift + enter. And now that you know how to work with Jupyter notebooks, you can always modify the notebooks with new code to test your understanding.
134
+
The same thing goes for working through a Readme. The Readmes will often assign data to variables, and it may be nice to work with data stored in those variables later on. So it's a good idea to press `shift + enter`, and now that you know how to work with Jupyter notebooks, you can always modify the notebooks with new code to test your understanding.
134
135
135
136
### Summary
136
137
137
-
In this lesson, we learned about Jupyter notebooks. We saw that in Jupyter notebooks, we can either be in insert mode or escape mode. While in insert mode, we can edit the cells, and undo changes within that cell with command+z or ctl+z. In escape mode, we can add cells with "b", delete a cell with "x", and undo deletion of a cell with "d". We can also change the type of a cell to markdown with "m" and to Python code with "j".
138
+
In this lesson, we learned about Jupyter notebooks. We saw that in Jupyter notebooks, we can either be in insert mode or escape mode. While in insert mode, we can edit the cells and undo changes within that cell with `command + z` or `ctl + z`. In escape mode, we can add cells with `b`, delete a cell with `x`, and undo deletion of a cell with `d`. We can also change the type of a cell to markdown with `m` and to Python code with `j`.
138
139
139
-
Then we saw how to work with Python code in Jupyter notebooks. We saw that to have our code in a cell executed, we should press shift + enter. And if we do not do this, then we may assume that variables are assigned in Python that is not assigned.
140
+
Then we saw how to work with Python code in Jupyter notebooks. We saw that to have our code in a cell executed, we need to press `shift + enter`. If we do not do this, then our variables that we assigned in Python are not going to be recognized by Python later on in our Jupyter notebook.
0 commit comments