对于以下数据框:
d = {'a':[10,11,12,13],'b':[20,21,22,23], 'c':[30,31,32,33]}
pd_df = pd.DataFrame(d)
pd_df.set_index('a')
b c
a
10 20 30
11 21 31
12 22 32
13 23 33
这段代码
pd_df.loc[10]
给出以下错误:
~/.local/lib/python3.6/site-packages/pandas/core/indexing.py in _validate_key(self, key, axis)
1789 if not ax.contains(key):
-> 1790 error()
1791 except TypeError as e:
~/.local/lib/python3.6/site-packages/pandas/core/indexing.py in error()
1784 .format(key=key,
-> 1785 axis=self.obj._get_axis_name(axis)))
1786
KeyError: 'the label [10] is not in the [index]'
我该如何修复它?
喵喵时光机
相关分类