1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import pandas as pd
b=pd.Series([9,8,7,6],['a','b','c','d'])
b Out[3]: a 9 b 8 c 7 d 6 dtype: int64
b.index Out[4]: Index(['a', 'b', 'c', 'd'], dtype='object')
b.values Out[5]: array([9, 8, 7, 6], dtype=int64)
b['b'] Out[6]: 8
b[1] Out[7]: 8
b[['c','d',0]] Traceback (most recent call last):
File "<ipython-input-8-9469556e3898>", line 1, in <module> b[['c','d',0]]
File "E:\Anaconda\lib\site-packages\pandas\core\series.py", line 910, in __getitem__ return self._get_with(key)
File "E:\Anaconda\lib\site-packages\pandas\core\series.py", line 958, in _get_with return self.loc[key]
File "E:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1767, in __getitem__ return self._getitem_axis(maybe_callable, axis=axis)
File "E:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1953, in _getitem_axis return self._getitem_iterable(key, axis=axis)
File "E:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1594, in _getitem_iterable keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
File "E:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1552, in _get_listlike_indexer keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
File "E:\Anaconda\lib\site-packages\pandas\core\indexing.py", line 1654, in _validate_read_indexer "Passing list-likes to .loc or [] with any missing labels "
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
b[['c','d','a']] Out[9]: c 7 d 6 a 9 dtype: int64
|