|
6 | 6 | "source": [
|
7 | 7 | "# Accessing a Series\n",
|
8 | 8 | "\n",
|
9 |
| -"There are multiple ways to get to the data that is stored in your `Series`. Let's explore the **`balances`** `Series`. \n", |
| 9 | +"There are multiple ways to get to the data stored in your `Series`. Let's explore the **`balances`** `Series`. \n", |
10 | 10 | "\n",
|
11 |
| -"Remember, the `Series` is indexed by username. The label is the username, the value is that user's balance." |
| 11 | +"Remember, the `Series` is indexed by username. The label is the username, the value is that user's cash balance." |
12 | 12 | ]
|
13 | 13 | },
|
14 | 14 | {
|
|
95 | 95 | "cell_type": "markdown",
|
96 | 96 | "metadata": {},
|
97 | 97 | "source": [
|
98 |
| -"The value is wrapped in a `NumPy.Scalar` so that it keeps it's data type and will play well with others.\n", |
| 98 | +"The value is wrapped in a [`NumPy.Scalar`](https://docs.scipy.org/doc/numpy-1.15.0/reference/arrays.scalars.html) so that it keeps it's data type and will play well with other data types and NumPy data structures.\n", |
99 | 99 | "\n",
|
100 |
| -"The same positional indexing works just as it does with a standard list." |
| 100 | +"The same positional indexing works just as it does with a standard list. The indices begin start with 0, and negative numbers can be used to access values from the end of the list." |
101 | 101 | ]
|
102 | 102 | },
|
103 | 103 | {
|
|
156 | 156 | "### `Series` behave like dictionaries"
|
157 | 157 | ]
|
158 | 158 | },
|
| 159 | +{ |
| 160 | +"cell_type": "code", |
| 161 | +"execution_count": 14, |
| 162 | +"metadata": {}, |
| 163 | +"outputs": [ |
| 164 | +{ |
| 165 | +"data": { |
| 166 | +"text/markdown": [ |
| 167 | +"The label pasan has a value of 20.0" |
| 168 | +], |
| 169 | +"text/plain": [ |
| 170 | +"<IPython.core.display.Markdown object>" |
| 171 | +] |
| 172 | +}, |
| 173 | +"metadata": {}, |
| 174 | +"output_type": "display_data" |
| 175 | +}, |
| 176 | +{ |
| 177 | +"data": { |
| 178 | +"text/markdown": [ |
| 179 | +"The label treasure has a value of 20.18" |
| 180 | +], |
| 181 | +"text/plain": [ |
| 182 | +"<IPython.core.display.Markdown object>" |
| 183 | +] |
| 184 | +}, |
| 185 | +"metadata": {}, |
| 186 | +"output_type": "display_data" |
| 187 | +}, |
| 188 | +{ |
| 189 | +"data": { |
| 190 | +"text/markdown": [ |
| 191 | +"The label ashley has a value of 1.05" |
| 192 | +], |
| 193 | +"text/plain": [ |
| 194 | +"<IPython.core.display.Markdown object>" |
| 195 | +] |
| 196 | +}, |
| 197 | +"metadata": {}, |
| 198 | +"output_type": "display_data" |
| 199 | +}, |
| 200 | +{ |
| 201 | +"data": { |
| 202 | +"text/markdown": [ |
| 203 | +"The label craig has a value of 42.42" |
| 204 | +], |
| 205 | +"text/plain": [ |
| 206 | +"<IPython.core.display.Markdown object>" |
| 207 | +] |
| 208 | +}, |
| 209 | +"metadata": {}, |
| 210 | +"output_type": "display_data" |
| 211 | +} |
| 212 | +], |
| 213 | +"source": [ |
| 214 | +"for label, value in balances.items():\n", |
| 215 | +" render(\"The label {} has a value of {}\".format(label, value))" |
| 216 | +] |
| 217 | +}, |
159 | 218 | {
|
160 | 219 | "cell_type": "code",
|
161 | 220 | "execution_count": 6,
|
|
259 | 318 | "cell_type": "markdown",
|
260 | 319 | "metadata": {},
|
261 | 320 | "source": [
|
262 |
| -"## Accessing More Explicitly\n", |
| 321 | +"## Accessing More Explicitly with `loc` and `iloc`\n", |
263 | 322 | "\n",
|
264 |
| -"We are using indexing which can *either* be a label *or* a positional index. This can get confusing. It's possible to be more explicit, [which yes wise Pythonista](https://www.python.org/dev/peps/pep-0020/), is always better than implicit.\n", |
| 323 | +"So far we have used a label and a positional index to access the value. This can get confusing as to what is being used, a label or a position. Because of this ambiguity, it is possible to be more explicit, [which yes wise Pythonista](https://www.python.org/dev/peps/pep-0020/), is always better than implicit.\n", |
265 | 324 | "\n",
|
266 | 325 | "A `Series` exposes a property named `loc` which can be used to explicitly lookup by label based indices only."
|
267 | 326 | ]
|
|
321 | 380 | "## Accessing by Slice\n",
|
322 | 381 | "Like a NumPy array, a `Series` also provides a way to use slices to get different portions of the data, returned as a `Series`. \n",
|
323 | 382 | "\n",
|
324 |
| -"*NOTE*: Slicing with indices vs. labels behaves differently. The latter is inclusive." |
| 383 | +"*WARNING*: Slicing with indices vs. labels behaves differently. The latter is inclusive." |
325 | 384 | ]
|
326 | 385 | },
|
327 | 386 | {
|
328 | 387 | "cell_type": "markdown",
|
329 | 388 | "metadata": {},
|
330 | 389 | "source": [
|
331 | 390 | "### Slicing by Positional Index\n",
|
332 |
| -"When using positional indices, the slice is exclusive..." |
| 391 | +"When using positional indices, the slice is exclusive. The last item **is not** included." |
333 | 392 | ]
|
334 | 393 | },
|
335 | 394 | {
|
|
362 | 421 | "metadata": {},
|
363 | 422 | "source": [
|
364 | 423 | "### Slicing by Label\n",
|
365 |
| -"When using labels, the slice is inclusive..." |
| 424 | +"When using labels, the slice is inclusive. The last item **is** included." |
366 | 425 | ]
|
367 | 426 | },
|
368 | 427 | {
|
|
0 commit comments