Skip to content

Commit 211f47a

Browse files
committed
Modify the notebooks
1 parent 8b500f5 commit 211f47a

File tree

2 files changed

+36
-136
lines changed

2 files changed

+36
-136
lines changed

pandas-example.ipynb

+31-35
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"Copied from [https://github.com/jakevdp/PythonDataScienceHandbook](https://github.com/jakevdp/PythonDataScienceHandbook)"
14+
"Copied from [https://github.com/jakevdp/PythonDataScienceHandbook](https://github.com/jakevdp/PythonDataScienceHandbook) with modifications to demonstrate notebook diffing."
1515
]
1616
},
1717
{
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
2121
"One of the essential pieces of NumPy is the ability to perform quick element-wise operations, both with basic arithmetic (addition, subtraction, multiplication, etc.) and with more sophisticated operations (trigonometric functions, exponential and logarithmic functions, etc.).\n",
22-
"Pandas inherits much of this functionality from NumPy, and the ufuncs that we introduced in [Computation on NumPy Arrays: Universal Functions](02.03-Computation-on-arrays-ufuncs.ipynb) are key to this.\n",
22+
"Pandas inherits much of this functionality from NumPy, and the ufuncs that we introduced in [Computation on NumPy Arrays: Universal Functions](https://gitnotebooks.com/blog) are key to this.\n",
2323
"\n",
2424
"Pandas includes a couple useful twists, however: for unary operations like negation and trigonometric functions, these ufuncs will *preserve index and column labels* in the output, and for binary operations such as addition and multiplication, Pandas will automatically *align indices* when passing the objects to the ufunc.\n",
2525
"This means that keeping the context of data and combining data from different sources–both potentially error-prone tasks with raw NumPy arrays–become essentially foolproof ones with Pandas.\n",
@@ -28,7 +28,7 @@
2828
},
2929
{
3030
"cell_type": "code",
31-
"execution_count": 121,
31+
"execution_count": 26,
3232
"metadata": {
3333
"collapsed": true
3434
},
@@ -48,7 +48,7 @@
4848
},
4949
{
5050
"cell_type": "code",
51-
"execution_count": 122,
51+
"execution_count": 27,
5252
"metadata": {
5353
"collapsed": false
5454
},
@@ -68,7 +68,7 @@
6868
},
6969
{
7070
"cell_type": "code",
71-
"execution_count": 123,
71+
"execution_count": 28,
7272
"metadata": {
7373
"collapsed": false
7474
},
@@ -77,26 +77,26 @@
7777
"data": {
7878
"text/plain": [
7979
"0 2.0\n",
80-
"1 5.0\n",
81-
"2 9.0\n",
82-
"3 5.0\n",
80+
"1 3.0\n",
81+
"2 3.0\n",
82+
"3 -5.0\n",
8383
"dtype: float64"
8484
]
8585
},
86-
"execution_count": 123,
86+
"execution_count": 28,
8787
"metadata": {},
8888
"output_type": "execute_result"
8989
}
9090
],
9191
"source": [
92-
"A.add(B, fill_value=0)"
92+
"A.subtract(B, fill_value=0)"
9393
]
9494
},
9595
{
9696
"cell_type": "markdown",
9797
"metadata": {},
9898
"source": [
99-
"Notice that indices are aligned correctly irrespective of their order in the two objects, and indices in the result are sorted.\n",
99+
"Observe that the indices align accurately regardless of their sequence in the two objects, and the result's indices are organized in ascending order.\n",
100100
"As was the case with ``Series``, we can use the associated object's arithmetic method and pass any desired ``fill_value`` to be used in place of missing entries.\n",
101101
"Here we'll fill with the mean of all values in ``A`` (computed by first stacking the rows of ``A``):"
102102
]
@@ -144,40 +144,36 @@
144144
" <th></th>\n",
145145
" <th>A</th>\n",
146146
" <th>B</th>\n",
147-
" <th>C</th>\n",
148147
" </tr>\n",
149148
" </thead>\n",
150149
" <tbody>\n",
151150
" <tr>\n",
152151
" <th>0</th>\n",
153152
" <td>19.00</td>\n",
154-
" <td>20.00</td>\n",
155-
" <td>16.75</td>\n",
153+
" <td>26.0</td>\n",
156154
" </tr>\n",
157155
" <tr>\n",
158156
" <th>1</th>\n",
159157
" <td>8.00</td>\n",
160-
" <td>3.00</td>\n",
161-
" <td>12.75</td>\n",
158+
" <td>19.0</td>\n",
162159
" </tr>\n",
163160
" <tr>\n",
164161
" <th>2</th>\n",
165-
" <td>16.75</td>\n",
166-
" <td>10.75</td>\n",
167-
" <td>12.75</td>\n",
162+
" <td>53.0</td>\n",
163+
" <td>56.0</td>\n",
168164
" </tr>\n",
169165
" </tbody>\n",
170166
"</table>\n",
171167
"</div>"
172168
],
173169
"text/plain": [
174-
" A B C\n",
175-
"0 19.00 20.00 16.75\n",
176-
"1 8.00 3.00 12.75\n",
177-
"2 16.75 10.75 12.75"
170+
" A B C\n",
171+
"0 10.0 26.0 55.0\n",
172+
"1 16.0 19.0 55.0\n",
173+
"2 53.0 56.0 52.0"
178174
]
179175
},
180-
"execution_count": 127,
176+
"execution_count": 30,
181177
"metadata": {},
182178
"output_type": "execute_result"
183179
}
@@ -200,7 +196,7 @@
200196
"# Large cells? No problem. Cells are collapsed to showcase the diff\n",
201197
"# Large cells? No problem. Cells are collapsed to showcase the diff\n",
202198
"\n",
203-
"fill = A.stack().mean()\n",
199+
"fill = A.stack().sum()\n",
204200
"A.add(B, fill_value=fill)\n",
205201
"\n",
206202
"# Large cells? No problem. Cells are collapsed to showcase the diff\n",
@@ -225,7 +221,7 @@
225221
"cell_type": "markdown",
226222
"metadata": {},
227223
"source": [
228-
"## Ufuncs: Operations Between DataFrame and Series\n",
224+
"## Ufuncs: Operations Between DataFrame and Series with a changed header\n",
229225
"\n",
230226
"When performing operations between a ``DataFrame`` and a ``Series``, the index and column alignment is similarly maintained.\n",
231227
"Operations between a ``DataFrame`` and a ``Series`` are similar to operations between a two-dimensional and one-dimensional NumPy array.\n",
@@ -234,20 +230,20 @@
234230
},
235231
{
236232
"cell_type": "code",
237-
"execution_count": 128,
233+
"execution_count": 31,
238234
"metadata": {
239235
"collapsed": false
240236
},
241237
"outputs": [
242238
{
243239
"data": {
244240
"text/plain": [
245-
"array([[1, 5, 5, 9],\n",
246-
" [3, 5, 1, 9],\n",
247-
" [1, 9, 3, 7]])"
241+
"array([[7, 7, 2, 5],\n",
242+
" [4, 1, 7, 5],\n",
243+
" [1, 4, 0, 9]])"
248244
]
249245
},
250-
"execution_count": 128,
246+
"execution_count": 31,
251247
"metadata": {},
252248
"output_type": "execute_result"
253249
}
@@ -259,7 +255,7 @@
259255
},
260256
{
261257
"cell_type": "code",
262-
"execution_count": 129,
258+
"execution_count": 32,
263259
"metadata": {
264260
"collapsed": false
265261
},
@@ -268,11 +264,11 @@
268264
"data": {
269265
"text/plain": [
270266
"array([[ 0, 0, 0, 0],\n",
271-
" [ 2, 0, -4, 0],\n",
272-
" [ 0, 4, -2, -2]])"
267+
" [-3, -6, 5, 0],\n",
268+
" [-6, -3, -2, 4]])"
273269
]
274270
},
275-
"execution_count": 129,
271+
"execution_count": 32,
276272
"metadata": {},
277273
"output_type": "execute_result"
278274
}

0 commit comments

Comments
 (0)