使用Pandax Corr矩阵获取KeyError

时间:2019-06-05 16:52:27

标签: python pandas

我使用熊猫读取了一个csv文件,我可以从数据框中读取所有列,但是当我尝试检查某些功能的相关矩阵时却遇到了一个棘手的keyerror错误。

def read_csv(path):
    return pd.read_csv(path, skipinitialspace = True)

data = read_csv(r'C:\Users\SAM\Documents\PYTHON\MACHINE\dataset\data.csv')

data['Release Clause'][0]
>>> '€226.5M' #works fine

corr_matrix = data.corr()
corr_matrix['Release Clause'].sort_values(ascending=False)



---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)

C:\ProgramData\Miniconda3\envs\machine\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   3078                 return self._engine.get_loc(key)
   3079             except KeyError:
-> 3080                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   3081 
   3082         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'Release Clause'

0 个答案:

没有答案