import pandas df6 = pandas.read_csv("https://www.pythonhow.com/supermarkets.csv")df6.set_index('test')我希望输出添加一个行标题“测试”,但在我的 jupyter 笔记本中返回以下错误。KeyError Traceback (most recent call last)c:\users\sunair raj\appdata\local\programs\python\python37-32\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 3077 try:-> 3078 return self._engine.get_loc(key) 3079 except KeyError: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: 'fdfdf'在处理上述异常的过程中,又发生了一个异常:
2 回答

慕村9548890
TA贡献1884条经验 获得超4个赞
.set_index()
正在尝试获取一列并将其设为索引。由于您没有任何名为 的列test
,因此它失败了。
不确定您是如何收到您发布的错误消息的,因为fdfdf
找不到任何地方。
你到底想做什么?输出应该是什么样的?
添加回答
举报
0/150
提交
取消