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
+19-78Lines changed: 19 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -5,71 +5,54 @@
5
5
6
6
In the past few lessons, we have learned about working with different types of data in Python: strings, numbers (ints and floats), and booleans. Now let's put that knowledge into action.
7
7
8
-
In this lesson we'll imagine that you just stopped by an Python programming conference and met a few people there. You exchanged some information with a very industrious person who you met, and want to use your programming skills to format this information correctly.
8
+
In this lesson we'll imagine that we were at a nice social gathering and exchanged business cards with a few people. One of the business cards belongs to Art Vandelay, a new travel agent. We want to use our programming skills to format this information correctly.
9
9
10
10
### Learning Objectives
11
11
* Manipulate strings with built-in methods
12
12
* Practice coercing data types and changing numbers
13
13
14
14
### Here to mingle
15
15
16
-
The next morning you take out the business card, ready to format it using your programming skills, and here is what you find.
16
+
The next morning we take out the business card, ready to format it using our programming skills, and here is what we find.
Yea, he may not be the best person to get to know. But we know that when people fill out forms, they misenter information all of the time. As a celebrity once said, "I'm really getting into the Internet lately, I just wish it were more organized."
20
+
Yea, Mr. Vandelay may not be the best person to get to know or the best at designing business cards, but like Mr. Vandelay, we know that people misenter information on forms all the time.
21
21
22
-
And as data scientists, we also see the need of organizing and cleaning data to then make sense of it. So let's get to work.
22
+
So as data scientists, we often need to clean and organize data before we can make sense of it. Let's get to work.
23
23
24
-
### Solving your first lab
24
+
### Solving our first lab
25
25
26
-
This is your first lab, and here you'll see that we have provided some data for you. Next to the data, you will see a comment indicating what the data should look after you change it. Let's do the first one together. For example, let's say we want to capitalize all of the letters of "art vandlay" (to remind ourselves of how he made his introduction). You'll see the following:
26
+
This is our first lab, and here we'll see that there is some data already provided for us. Next to the data, we will see a comment indicating what the data should look like after we change it. Let's do the first one together.
27
+
28
+
For example, let's say we want to capitalize all of the letters of "art vandlay". We'll see the following:
27
29
28
30
29
31
```python
30
32
"art vandelay"# 'ART VANDELAY'
31
33
```
32
34
35
+
Notice that there is no output below the gray code above. This is because Jupyter notebooks do not automatically run our code - so they do not automatically know the output. To display the output, we must **run** the code by clicking on the gray cell and then pressing shift + enter. Let's try it in the cell above and see our output appear below.
33
36
34
-
35
-
36
-
'art vandelay'
37
-
38
-
39
-
40
-
That hash tag to the right is a comment. Comments are used for programmers to annotate their code. But a comment has no impact on the code.
37
+
Ok, once we see the output take a look at the hash tag to the right of the string. The hash tag to the right is a comment. Comments are used for programmers to annotate their code, but a comment has no impact on the code. See this by running the next cell below (again, press shift + enter).
41
38
42
39
43
40
```python
44
41
'hello'
45
42
### whattttt
46
43
```
47
44
45
+
If we press shift+enter on the cell above to run the code, we will see that Python happily ignores the comment. So here (and in future labs), a comment will be provided to indicate what we should see as the return value of our code. When we press shift+enter, and the output below matches the comment to the right of our code, we did it correctly.
48
46
47
+
> In future labs, Learn will check our code to ensure that we did it correctly. But for our first lab, this works fine.
49
48
50
-
51
-
'hello'
52
-
53
-
54
-
55
-
If you press shift+enter to run the code in the cell, you will see that Python happily ignores the comment. So in labs, we provide the comment to indicate what you should see as the return value of your code. When you press shift+enter, and the output below matches the comment to the right of your code, you did it correctly.
56
-
57
-
> In future labs, Learn will check your code to ensure that you did it correctly. But for your first lab, this works fine.
58
-
59
-
And change it to the following:
49
+
To get our output to match the comment we will change it to the following:
60
50
61
51
62
52
```python
63
53
"art vandelay".upper() # 'ART VANDELAY'
64
54
```
65
55
66
-
67
-
68
-
69
-
'ART VANDELAY'
70
-
71
-
72
-
73
56
### Get going with strings
74
57
75
58
First use the `title` method to capitalize the first letter of each word in "art vandelay"`.
@@ -79,83 +62,41 @@ First use the `title` method to capitalize the first letter of each word in "art
79
62
"art vandelay"# 'Art Vandelay'
80
63
```
81
64
82
-
83
-
84
-
85
-
'art vandelay'
86
-
87
-
88
-
89
65
Now let's uppercase all of the letters of "Ceo".
90
66
91
67
92
68
```python
93
69
"Ceo"# 'CEO'
94
70
```
95
71
96
-
97
-
98
-
99
-
'Ceo'
100
-
101
-
102
-
103
-
Now write a method that answers a question about our email addresses. Every email address should end with ".com". Use your knowledge of string methods to check if the email address ends with ".com" and return `True` or `False` accordingly.
72
+
Next, write a method that answers a question about our email addresses. Every email address should end with ".com". We can use our knowledge of string methods to check if the email address ends with ".com" and return `True` or `False` accordingly.
104
73
105
74
106
75
```python
107
-
"art.vandelay@vandelay.cop"# False
76
+
"art.vandelay@vandelay.co"# False
108
77
```
109
78
110
-
111
-
112
-
113
-
'art.vandelay@vandelay.cop'
114
-
115
-
116
-
117
-
As you can see, the website "vandelay.com" is not preceded by `"www."`. Use the plus sign to change the website 'vandelay.com' to the string `'www.vandelay.com'`.
79
+
As you can see below, the website "vandelay.com" is not preceded by `"www."`. We can perform what is called string interpolation to fix this! Use the plus sign, `'+'`, to change the website `'vandelay.com'` to the string `'www.vandelay.com'` by prepending `'www.'`.
118
80
119
81
120
82
```python
121
83
'vandelay.com'# 'www.vandelay.com'
122
84
```
123
85
124
-
125
-
126
-
127
-
'vandelay.com'
128
-
129
-
130
-
131
86
### Working with numbers
132
87
133
-
Finally, Mr. Vandelay gave us his phone number, but he actually has a second number different ones listed. All three numbers are the same except for the ending. Coerce the string of his phone numberto an `int` and add one, then add two to change the number.
88
+
Finally, Mr. Vandelay gave us his phone number, but he actually has two other phone numbers that are different from the one listed. All three numbers are basically the same with the excepion of the ending. Below, start by coercing the first phone number, which is currently a string, to an `int` and add one. Next do the same to the second phone number but increase it by two.
134
89
135
90
136
91
```python
137
92
"7285553334"# 7285553335
138
93
```
139
94
140
95
141
-
142
-
143
-
'7285553334'
144
-
145
-
146
-
147
-
148
96
```python
149
97
"7285553334"# 7285553336
150
98
```
151
99
152
-
153
-
154
-
155
-
'7285553334'
156
-
157
-
158
-
159
100
### Summary
160
101
161
-
Your first lab done! Sweet. In this lab, you practiced working with string methods to operate on and answer questions about strings. You wrote methods that return Booleans. And you changed strings to an `int`to then perform addition. So much of working with data, is ensuring that our data is properly formatted so we can then operate on it and in this lab you saw how to use code to just that.
102
+
Our first lab is done! Sweet. In this lab, we practiced working with string methods to operate on and answer questions about strings. We wrote methods that return Booleans and changed strings to intergers in order to perform addition. So much of working with data is ensuring that it is properly formatted so we can then operate on it, and in this lab, we saw how to use code to do just that.
Copy file name to clipboardExpand all lines: index.ipynb
+17-15Lines changed: 17 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@
20
20
"source": [
21
21
"In the past few lessons, we have learned about working with different types of data in Python: strings, numbers (ints and floats), and booleans. Now let's put that knowledge into action.\n",
22
22
"\n",
23
-
"In this lesson we'll imagine that at a nice social gathering you exchanged business cards with a few people. One of the business cards belongs to Art Vandelay, a new travel agent. You want to use your programming skills to format this information correctly. "
23
+
"In this lesson we'll imagine that we were at a nice social gathering and exchanged business cards with a few people. One of the business cards belongs to Art Vandelay, a new travel agent. We want to use our programming skills to format this information correctly. "
24
24
]
25
25
},
26
26
{
@@ -43,7 +43,7 @@
43
43
"cell_type": "markdown",
44
44
"metadata": {},
45
45
"source": [
46
-
"The next morning you take out the business card, ready to format it using your programming skills, and here is what you find."
46
+
"The next morning we take out the business card, ready to format it using our programming skills, and here is what we find."
47
47
]
48
48
},
49
49
{
@@ -66,16 +66,16 @@
66
66
"cell_type": "markdown",
67
67
"metadata": {},
68
68
"source": [
69
-
"### Solving your first lab"
69
+
"### Solving our first lab"
70
70
]
71
71
},
72
72
{
73
73
"cell_type": "markdown",
74
74
"metadata": {},
75
75
"source": [
76
-
"This is your first lab, and here you'll see that we have provided some data for you. Next to the data, you will see a comment indicating what the data should look like after you change it. Let's do the first one together. \n",
76
+
"This is our first lab, and here we'll see that there is some data already provided for us. Next to the data, we will see a comment indicating what the data should look like after we change it. Let's do the first one together. \n",
77
77
"\n",
78
-
"For example, let's say we want to capitalize all of the letters of \"art vandlay\". You'll see the following:"
78
+
"For example, let's say we want to capitalize all of the letters of \"art vandlay\". We'll see the following:"
79
79
]
80
80
},
81
81
{
@@ -93,14 +93,14 @@
93
93
"cell_type": "markdown",
94
94
"metadata": {},
95
95
"source": [
96
-
"Notice that there is no output below the gray code above. This is because Jupyter notebooks do not automatically run our code - so they do not automatically know the output. To display the output, you must **run** the code by clicking on the gray cell and then pressing shift + enter. Try it above and you will see output below the cell."
96
+
"Notice that there is no output below the gray code above. This is because Jupyter notebooks do not automatically run our code - so they do not automatically know the output. To display the output, we must **run** the code by clicking on the gray cell and then pressing shift + enter. Let's try it in the cell above and see our output appear below."
97
97
]
98
98
},
99
99
{
100
100
"cell_type": "markdown",
101
101
"metadata": {},
102
102
"source": [
103
-
"Ok, once you see the output take a look at the hash tag to the right of the string. The hash tag to the right is a comment. Comments are used for programmers to annotate their code, but a comment has no impact on the code. See this by running the next cell below (again, press shift + enter)."
103
+
"Ok, once we see the output take a look at the hash tag to the right of the string. The hash tag to the right is a comment. Comments are used for programmers to annotate their code, but a comment has no impact on the code. See this by running the next cell below (again, press shift + enter)."
104
104
]
105
105
},
106
106
{
@@ -119,21 +119,21 @@
119
119
"cell_type": "markdown",
120
120
"metadata": {},
121
121
"source": [
122
-
"If you press shift+enter on the cell above to run the code, you will see that Python happily ignores the comment. So here (and in future labs), we will provide the comment to indicate what you should see as the return value of your code. When you press shift+enter, and the output below matches the comment to the right of your code, you did it correctly."
122
+
"If we press shift+enter on the cell above to run the code, we will see that Python happily ignores the comment. So here (and in future labs), a comment will be provided to indicate what we should see as the return value of our code. When we press shift+enter, and the output below matches the comment to the right of our code, we did it correctly."
123
123
]
124
124
},
125
125
{
126
126
"cell_type": "markdown",
127
127
"metadata": {},
128
128
"source": [
129
-
"> In future labs, Learn will check your code to ensure that you did it correctly. But for your first lab, this works fine."
129
+
"> In future labs, Learn will check our code to ensure that we did it correctly. But for our first lab, this works fine."
130
130
]
131
131
},
132
132
{
133
133
"cell_type": "markdown",
134
134
"metadata": {},
135
135
"source": [
136
-
"To get our output to match comment we will change it to the following:"
136
+
"To get our output to match the comment we will change it to the following:"
137
137
]
138
138
},
139
139
{
@@ -194,13 +194,15 @@
194
194
"cell_type": "markdown",
195
195
"metadata": {},
196
196
"source": [
197
-
"Next, write a method that answers a question about our email addresses. Every email address should end with \".com\". Use your knowledge of string methods to check if the email address ends with \".com\" and return `True` or `False` accordingly. "
197
+
"Next, write a method that answers a question about our email addresses. Every email address should end with \".com\". We can use our knowledge of string methods to check if the email address ends with \".com\" and return `True` or `False` accordingly. "
198
198
]
199
199
},
200
200
{
201
201
"cell_type": "code",
202
202
"execution_count": null,
203
-
"metadata": {},
203
+
"metadata": {
204
+
"collapsed": true
205
+
},
204
206
"outputs": [],
205
207
"source": [
206
208
"\"art.vandelay@vandelay.co\" # False"
@@ -210,7 +212,7 @@
210
212
"cell_type": "markdown",
211
213
"metadata": {},
212
214
"source": [
213
-
"As you can see below, the website \"vandelay.com\" is not preceded by `\"www.\"`. We can perform what is called string interpolation to fix this! Use the plus sign, `+`, to change the website `'vandelay.com'` to the string `'www.vandelay.com'` by prepending `'www.'`."
215
+
"As you can see below, the website \"vandelay.com\" is not preceded by `\"www.\"`. We can perform what is called string interpolation to fix this! Use the plus sign, `'+'`, to change the website `'vandelay.com'` to the string `'www.vandelay.com'` by prepending `'www.'`."
214
216
]
215
217
},
216
218
{
@@ -236,7 +238,7 @@
236
238
"cell_type": "markdown",
237
239
"metadata": {},
238
240
"source": [
239
-
"Finally, Mr. Vandelay gave us his phone number, but he actually has a second phone number that is different from the one listed. All three numbers are basically the same with the excepion of the ending. Below, start by coercing each phone number, which are currently strings, to an `int` and add one to the first and add two to the second to change the numbers."
241
+
"Finally, Mr. Vandelay gave us his phone number, but he actually has two other phone numbers that are different from the one listed. All three numbers are basically the same with the excepion of the ending. Below, start by coercing the first phone number, which is currently a string, to an `int` and add one. Next do the same to the second phone number but increase it by two."
240
242
]
241
243
},
242
244
{
@@ -272,7 +274,7 @@
272
274
"cell_type": "markdown",
273
275
"metadata": {},
274
276
"source": [
275
-
"Your first lab done! Sweet. In this lab, you practiced working with string methods to operate on and answer questions about strings. You wrote methods that return Booleans and changed strings to intergers in order to perform addition. So much of working with data is ensuring that it is properly formatted so we can then operate on it, and in this lab, you saw how to use code to just that."
277
+
"Our first lab is done! Sweet. In this lab, we practiced working with string methods to operate on and answer questions about strings. We wrote methods that return Booleans and changed strings to intergers in order to perform addition. So much of working with data is ensuring that it is properly formatted so we can then operate on it, and in this lab, we saw how to use code to do just that."
0 commit comments