@@ -73,16 +73,16 @@ In this lesson, we will explore **ways to access different parts of the data** i
73
73
<pre class =" output " >
74
74
<div class =" output_label " >output</div >
75
75
<code class =" text " >
76
- Requirement already satisfied: pandas in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (0.23.0)
77
- Requirement already satisfied: matplotlib in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (2.2.2)
78
- Requirement already satisfied: numpy>=1.9 .0 in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from pandas) (1.14 .3)
79
- Requirement already satisfied: python-dateutil>=2.5.0 in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from pandas) (2.7.3 )
80
- Requirement already satisfied: pytz>=2011k in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from pandas) (2018.4 )
81
- Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from matplotlib) (2.2.0)
82
- Requirement already satisfied: kiwisolver>=1.0.1 in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from matplotlib) (1.0.1)
83
- Requirement already satisfied: cycler>=0 .10 in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from matplotlib) (0.10 .0)
84
- Requirement already satisfied: six>=1 .10 in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from matplotlib) (1.11 .0)
85
- Requirement already satisfied: setuptools in /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib) (39.2 .0)
76
+ Requirement already satisfied: pandas in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (0.23.0)
77
+ Requirement already satisfied: matplotlib in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (2.2.2)
78
+ Requirement already satisfied: python-dateutil>=2.5 .0 in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from pandas) (2.7 .3)
79
+ Requirement already satisfied: pytz>=2011k in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from pandas) (2018.4 )
80
+ Requirement already satisfied: numpy>=1.9.0 in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from pandas) (1.14.3 )
81
+ Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from matplotlib) (2.2.0)
82
+ Requirement already satisfied: kiwisolver>=1.0.1 in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from matplotlib) (1.0.1)
83
+ Requirement already satisfied: six>=1 .10 in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from matplotlib) (1.11 .0)
84
+ Requirement already satisfied: cycler>=0 .10 in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from matplotlib) (0.10 .0)
85
+ Requirement already satisfied: setuptools in /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib) (39.1 .0)
86
86
87
87
</code >
88
88
</pre >
@@ -107,7 +107,7 @@ We will continue to use the surveys dataset that we worked with in the last less
107
107
import pandas as pd
108
108
109
109
# Read in the survey CSV
110
- surveys_df = pd.read_csv(" data/ surveys.csv" )
110
+ surveys_df = pd.read_csv(" surveys.csv" )
111
111
```
112
112
113
113
@@ -294,105 +294,90 @@ surveys_df[['species_id', 'site_id']].head()
294
294
295
295
296
296
297
- ``` python
297
+ What happens if you ask for a column that doesn't exist?
298
298
299
- # What happens if you ask for a column that doesn't exist?
299
+ ``` python
300
300
surveys_df[' speciess' ]
301
-
302
-
303
301
```
304
302
303
+ Outputs:
305
304
306
- ---------------------------------------------------------------------------
307
-
308
- KeyError Traceback (most recent call last)
309
-
310
- ~/.local/share/virtualenvs/python-workshop-base-LFzz33nP/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
311
- 3062 try:
312
- -> 3063 return self._engine.get_loc(key)
313
- 3064 except KeyError:
314
-
315
-
316
- pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
317
-
318
-
319
- pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
320
-
321
-
322
- pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
323
305
324
306
325
- pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
326
307
327
308
328
- KeyError: 'speciess'
329
-
330
-
331
- During handling of the above exception, another exception occurred:
332
-
333
-
334
- KeyError Traceback (most recent call last)
335
-
336
- <ipython-input-7-8c68e7647ac0> in <module>()
337
- 1
338
- 2 # What happens if you ask for a column that doesn't exist?
339
- ----> 3 surveys_df['speciess']
340
-
341
-
342
- ~/.local/share/virtualenvs/python-workshop-base-LFzz33nP/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
343
- 2683 return self._getitem_multilevel(key)
344
- 2684 else:
345
- -> 2685 return self._getitem_column(key)
346
- 2686
347
- 2687 def _getitem_column(self, key):
348
-
349
-
350
- ~/.local/share/virtualenvs/python-workshop-base-LFzz33nP/lib/python3.6/site-packages/pandas/core/frame.py in _getitem_column(self, key)
351
- 2690 # get column
352
- 2691 if self.columns.is_unique:
353
- -> 2692 return self._get_item_cache(key)
354
- 2693
355
- 2694 # duplicate columns & possible reduce dimensionality
309
+ ``` python
310
+ -------------------------------------------------------------------------- -
311
+ KeyError Traceback (most recent call last)
312
+ / Applications/ anaconda/ lib/ python3.6/ site- packages/ pandas/ core/ indexes/ base.py in get_loc(self , key, method, tolerance)
313
+ 2392 try :
314
+ -> 2393 return self ._engine.get_loc(key)
315
+ 2394 except KeyError :
356
316
317
+ pandas/ _libs/ index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/ _libs/ index.c:5239 )()
357
318
358
- ~/.local/share/virtualenvs/python-workshop-base-LFzz33nP/lib/python3.6/site-packages/pandas/core/generic.py in _get_item_cache(self, item)
359
- 2484 res = cache.get(item)
360
- 2485 if res is None:
361
- -> 2486 values = self._data.get(item)
362
- 2487 res = self._box_item_values(item, values)
363
- 2488 cache[item] = res
319
+ pandas/ _libs/ index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/ _libs/ index.c:5085 )()
364
320
321
+ pandas/ _libs/ hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/ _libs/ hashtable.c:20405 )()
365
322
366
- ~/.local/share/virtualenvs/python-workshop-base-LFzz33nP/lib/python3.6/site-packages/pandas/core/internals.py in get(self, item, fastpath)
367
- 4113
368
- 4114 if not isna(item):
369
- -> 4115 loc = self.items.get_loc(item)
370
- 4116 else:
371
- 4117 indexer = np.arange(len(self.items))[isna(self.items)]
323
+ pandas/ _libs/ hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/ _libs/ hashtable.c:20359 )()
372
324
325
+ KeyError : ' speciess'
373
326
374
- ~/.local/share/virtualenvs/python-workshop-base-LFzz33nP/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
375
- 3063 return self._engine.get_loc(key)
376
- 3064 except KeyError:
377
- -> 3065 return self._engine.get_loc(self._maybe_cast_indexer(key))
378
- 3066
379
- 3067 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
327
+ During handling of the above exception, another exception occurred:
380
328
329
+ KeyError Traceback (most recent call last)
330
+ < ipython- input - 7 - 7d65fa0158b8 > in < module> ()
331
+ 1
332
+ 2 # What happens if you ask for a column that doesn't exist?
333
+ ---- > 3 surveys_df[' speciess' ]
334
+ 4
381
335
382
- pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
336
+ / Applications/ anaconda/ lib/ python3.6/ site- packages/ pandas/ core/ frame.py in __getitem__ (self , key)
337
+ 2060 return self ._getitem_multilevel(key)
338
+ 2061 else :
339
+ -> 2062 return self ._getitem_column(key)
340
+ 2063
341
+ 2064 def _getitem_column (self , key ):
383
342
343
+ / Applications/ anaconda/ lib/ python3.6/ site- packages/ pandas/ core/ frame.py in _getitem_column(self , key)
344
+ 2067 # get column
345
+ 2068 if self .columns.is_unique:
346
+ -> 2069 return self ._get_item_cache(key)
347
+ 2070
348
+ 2071 # duplicate columns & possible reduce dimensionality
384
349
385
- pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
350
+ / Applications/ anaconda/ lib/ python3.6/ site- packages/ pandas/ core/ generic.py in _get_item_cache(self , item)
351
+ 1532 res = cache.get(item)
352
+ 1533 if res is None :
353
+ -> 1534 values = self ._data.get(item)
354
+ 1535 res = self ._box_item_values(item, values)
355
+ 1536 cache[item] = res
386
356
357
+ / Applications/ anaconda/ lib/ python3.6/ site- packages/ pandas/ core/ internals.py in get(self , item, fastpath)
358
+ 3588
359
+ 3589 if not isnull(item):
360
+ -> 3590 loc = self .items.get_loc(item)
361
+ 3591 else :
362
+ 3592 indexer = np.arange(len (self .items))[isnull(self .items)]
387
363
388
- pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
364
+ / Applications/ anaconda/ lib/ python3.6/ site- packages/ pandas/ core/ indexes/ base.py in get_loc(self , key, method, tolerance)
365
+ 2393 return self ._engine.get_loc(key)
366
+ 2394 except KeyError :
367
+ -> 2395 return self ._engine.get_loc(self ._maybe_cast_indexer(key))
368
+ 2396
369
+ 2397 indexer = self .get_indexer([key], method = method, tolerance = tolerance)
389
370
371
+ pandas/ _libs/ index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/ _libs/ index.c:5239 )()
390
372
391
- pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item ()
373
+ pandas/ _libs/ index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas / _libs / index.c: 5085 ) ()
392
374
375
+ pandas/ _libs/ hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/ _libs/ hashtable.c:20405 )()
393
376
394
- KeyError: 'speciess'
377
+ pandas / _libs / hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas / _libs / hashtable.c: 20359 )()
395
378
379
+ KeyError : ' speciess'
380
+ ```
396
381
397
382
398
383
@@ -877,7 +862,7 @@ the original data CSV file.
877
862
878
863
879
864
``` python
880
- surveys_df = pd.read_csv(" data/ surveys.csv" )
865
+ surveys_df = pd.read_csv(" surveys.csv" )
881
866
```
882
867
883
868
@@ -1084,7 +1069,7 @@ surveys_df.loc[[0, 10, 35549], :]
1084
1069
<pre class =" output " >
1085
1070
<div class =" output_label " >output</div >
1086
1071
<code class =" text " >
1087
- /Users/asha0035/.local/share/ virtualenvs/python-workshop-base-LFzz33nP /lib/python3.6/site-packages/pandas/core/indexing.py:1472: FutureWarning:
1072
+ /Users/perry/. virtualenvs/python-workshop-base-ufuVBSbV /lib/python3.6/site-packages/pandas/core/indexing.py:1472: FutureWarning:
1088
1073
Passing list-likes to .loc or [] with any missing label will raise
1089
1074
KeyError in the future, you can use .reindex() as an alternative.
1090
1075
@@ -5150,14 +5135,14 @@ stack_selection.plot(kind='bar', stacked=True)
5150
5135
<pre class =" output " >
5151
5136
<div style =" text-align : right ; margin : -1em ; padding : 0 ;" ><span style =" font-size : 0.5em ; color : grey " >output</span ></div >
5152
5137
<code class =" text " >
5153
- <matplotlib.axes._subplots.AxesSubplot at 0x10eccdc18 >
5138
+ <matplotlib.axes._subplots.AxesSubplot at 0x1083a6470 >
5154
5139
</code >
5155
5140
</pre >
5156
5141
5157
5142
5158
5143
5159
5144
5160
- ![ png] ( indexing_files/indexing_73_1 .png )
5145
+ ![ png] ( indexing_files/indexing_74_1 .png )
5161
5146
5162
5147
5163
5148
0 commit comments