leosmigel / analyzingalpha

474 stars 200 forks source link

Get an error trying to run your ipynb #3

Closed tae898 closed 3 years ago

tae898 commented 4 years ago

KeyError Traceback (most recent call last)

in () 6 7 # Get current S&P table and set header column ----> 8 sp500 = data[0].loc[1:,[0,1,6,7]] 9 columns = ['added_ticker', 'name', 'date', 'cik'] 10 sp500.columns = columns 5 frames /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in __getitem__(self, key) 1760 except (KeyError, IndexError, AttributeError): 1761 pass -> 1762 return self._getitem_tuple(key) 1763 else: 1764 # we by definition only have the 0th axis /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _getitem_tuple(self, tup) 1287 continue 1288 -> 1289 retval = getattr(retval, self.name)._getitem_axis(key, axis=i) 1290 1291 return retval /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis) 1952 raise ValueError("Cannot index with multidimensional key") 1953 -> 1954 return self._getitem_iterable(key, axis=axis) 1955 1956 # nested tuple slicing /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _getitem_iterable(self, key, axis) 1593 else: 1594 # A collection of keys -> 1595 keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False) 1596 return self.obj._reindex_with_indexers( 1597 {axis: [keyarr, indexer]}, copy=True, allow_dups=True /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _get_listlike_indexer(self, key, axis, raise_missing) 1551 1552 self._validate_read_indexer( -> 1553 keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing 1554 ) 1555 return keyarr, indexer /usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing) 1638 if missing == len(indexer): 1639 axis_name = self.obj._get_axis_name(axis) -> 1640 raise KeyError(f"None of [{key}] are in the [{axis_name}]") 1641 1642 # We (temporarily) allow for some missing keys with .loc, except in KeyError: "None of [Int64Index([0, 1, 6, 7], dtype='int64')] are in the [columns]"
leosmigel commented 3 years ago

Please see the updated article.