Digital modeling experience-data processing-pandas
Digital analog experience-data processing-pandas
Detailed explanation of the code: will be added next time
import pandas as pd
import numpy as np
# # Set panda display function
# pd.set_option('display.max_columns', 10)
# pd.set_option('display.max_rows', 100)
# pd.set_option('display.width', 100)
-------------------------------------------------- ----------------------------
ValueError Traceback (most recent call last)
File d:\Anaconda3\envs\guoguo\lib\site-packages\pandas\core\indexes\range.py:391, in RangeIndex.get_loc(self, key, method, tolerance)
390 try:
--> 391 return self._range.index(new_key)
392 except ValueError as err:
ValueError: -1 is not in range
?
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
d:\ai_py_3.9\Common code\pfda\chapter5.ipynb Cell 38 line 2
<a href='vscode-notebook-cell:/d:/ai_py_3.9/common code/pfda/chapter5.ipynb#X51sZmlsZQ==?line=0'>1</a> ser = pd.Series( np.arange(3.))
----> <a href='vscode-notebook-cell:/d:/ai_py_3.9/common code/pfda/chapter5.ipynb#X51sZmlsZQ==?line=1'>2</a> ser [-1]
File d:\Anaconda3\envs\guoguo\lib\site-packages\pandas\core\series.py:981, in Series.__getitem__(self, key)
978 return self._values[key]
980 elif key_is_scalar:
--> 981 return self._get_value(key)
983 if is_hashable(key):
984 # Otherwise index.get_value will raise InvalidIndexError
985 try:
986 # For labels that don't resolve as scalars like tuples and frozensets
File d:\Anaconda3\envs\guoguo\lib\site-packages\pandas\core\series.py:1089, in Series._get_value(self, label, takeable)
1086 return self._values[label]
1088 # Similar to Index.get_value, but we do not fall back to positional
-> 1089 loc = self.index.get_loc(label)
1090 return self.index._get_values_for_loc(self, loc, label)
File d:\Anaconda3\envs\guoguo\lib\site-packages\pandas\core\indexes\range.py:393, in RangeIndex.get_loc(self, key, method, tolerance)
391 return self._range.index(new_key)
392 except ValueError as err:
--> 393 raise KeyError(key) from err
394 self._check_indexing_error(key)
395 raise KeyError(key)
KeyError: -1