|
28 | 28 | },
|
29 | 29 | {
|
30 | 30 | "cell_type": "code",
|
31 |
| - "execution_count": 121, |
| 31 | + "execution_count": 26, |
32 | 32 | "metadata": {
|
33 | 33 | "collapsed": true
|
34 | 34 | },
|
|
48 | 48 | },
|
49 | 49 | {
|
50 | 50 | "cell_type": "code",
|
51 |
| - "execution_count": 122, |
| 51 | + "execution_count": 27, |
52 | 52 | "metadata": {
|
53 | 53 | "collapsed": false
|
54 | 54 | },
|
|
68 | 68 | },
|
69 | 69 | {
|
70 | 70 | "cell_type": "code",
|
71 |
| - "execution_count": 123, |
| 71 | + "execution_count": 28, |
72 | 72 | "metadata": {
|
73 | 73 | "collapsed": false
|
74 | 74 | },
|
|
77 | 77 | "data": {
|
78 | 78 | "text/plain": [
|
79 | 79 | "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", |
83 | 83 | "dtype: float64"
|
84 | 84 | ]
|
85 | 85 | },
|
86 |
| - "execution_count": 123, |
| 86 | + "execution_count": 28, |
87 | 87 | "metadata": {},
|
88 | 88 | "output_type": "execute_result"
|
89 | 89 | }
|
90 | 90 | ],
|
91 | 91 | "source": [
|
92 |
| - "A.add(B, fill_value=0)" |
| 92 | + "A.subtract(B, fill_value=0)" |
93 | 93 | ]
|
94 | 94 | },
|
95 | 95 | {
|
96 | 96 | "cell_type": "markdown",
|
97 | 97 | "metadata": {},
|
98 | 98 | "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", |
100 | 100 | "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",
|
101 | 101 | "Here we'll fill with the mean of all values in ``A`` (computed by first stacking the rows of ``A``):"
|
102 | 102 | ]
|
|
150 | 150 | " <tbody>\n",
|
151 | 151 | " <tr>\n",
|
152 | 152 | " <th>0</th>\n",
|
153 |
| - " <td>19.00</td>\n", |
154 |
| - " <td>20.00</td>\n", |
155 |
| - " <td>16.75</td>\n", |
| 153 | + " <td>10.0</td>\n", |
| 154 | + " <td>26.0</td>\n", |
| 155 | + " <td>55.0</td>\n", |
156 | 156 | " </tr>\n",
|
157 | 157 | " <tr>\n",
|
158 | 158 | " <th>1</th>\n",
|
159 |
| - " <td>8.00</td>\n", |
160 |
| - " <td>3.00</td>\n", |
161 |
| - " <td>12.75</td>\n", |
| 159 | + " <td>16.0</td>\n", |
| 160 | + " <td>19.0</td>\n", |
| 161 | + " <td>55.0</td>\n", |
162 | 162 | " </tr>\n",
|
163 | 163 | " <tr>\n",
|
164 | 164 | " <th>2</th>\n",
|
165 |
| - " <td>16.75</td>\n", |
166 |
| - " <td>10.75</td>\n", |
167 |
| - " <td>12.75</td>\n", |
| 165 | + " <td>53.0</td>\n", |
| 166 | + " <td>56.0</td>\n", |
| 167 | + " <td>52.0</td>\n", |
168 | 168 | " </tr>\n",
|
169 | 169 | " </tbody>\n",
|
170 | 170 | "</table>\n",
|
171 | 171 | "</div>"
|
172 | 172 | ],
|
173 | 173 | "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" |
| 174 | + " A B C\n", |
| 175 | + "0 10.0 26.0 55.0\n", |
| 176 | + "1 16.0 19.0 55.0\n", |
| 177 | + "2 53.0 56.0 52.0" |
178 | 178 | ]
|
179 | 179 | },
|
180 |
| - "execution_count": 127, |
| 180 | + "execution_count": 30, |
181 | 181 | "metadata": {},
|
182 | 182 | "output_type": "execute_result"
|
183 | 183 | }
|
184 | 184 | ],
|
185 | 185 | "source": [
|
186 |
| - "fill = A.stack().mean()\n", |
| 186 | + "fill = A.stack().sum()\n", |
187 | 187 | "A.add(B, fill_value=fill)"
|
188 | 188 | ]
|
189 | 189 | },
|
|
200 | 200 | },
|
201 | 201 | {
|
202 | 202 | "cell_type": "code",
|
203 |
| - "execution_count": 128, |
| 203 | + "execution_count": 31, |
204 | 204 | "metadata": {
|
205 | 205 | "collapsed": false
|
206 | 206 | },
|
207 | 207 | "outputs": [
|
208 | 208 | {
|
209 | 209 | "data": {
|
210 | 210 | "text/plain": [
|
211 |
| - "array([[1, 5, 5, 9],\n", |
212 |
| - " [3, 5, 1, 9],\n", |
213 |
| - " [1, 9, 3, 7]])" |
| 211 | + "array([[7, 7, 2, 5],\n", |
| 212 | + " [4, 1, 7, 5],\n", |
| 213 | + " [1, 4, 0, 9]])" |
214 | 214 | ]
|
215 | 215 | },
|
216 |
| - "execution_count": 128, |
| 216 | + "execution_count": 31, |
217 | 217 | "metadata": {},
|
218 | 218 | "output_type": "execute_result"
|
219 | 219 | }
|
|
225 | 225 | },
|
226 | 226 | {
|
227 | 227 | "cell_type": "code",
|
228 |
| - "execution_count": 129, |
| 228 | + "execution_count": 32, |
229 | 229 | "metadata": {
|
230 | 230 | "collapsed": false
|
231 | 231 | },
|
|
234 | 234 | "data": {
|
235 | 235 | "text/plain": [
|
236 | 236 | "array([[ 0, 0, 0, 0],\n",
|
237 |
| - " [ 2, 0, -4, 0],\n", |
238 |
| - " [ 0, 4, -2, -2]])" |
| 237 | + " [-3, -6, 5, 0],\n", |
| 238 | + " [-6, -3, -2, 4]])" |
239 | 239 | ]
|
240 | 240 | },
|
241 |
| - "execution_count": 129, |
| 241 | + "execution_count": 32, |
242 | 242 | "metadata": {},
|
243 | 243 | "output_type": "execute_result"
|
244 | 244 | }
|
|
0 commit comments