为了账号安全,请及时绑定邮箱和手机立即绑定

无法在python中使用pandas包使用set_index()

无法在python中使用pandas包使用set_index()

小唯快跑啊 2021-10-10 15:35:28
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找不到任何地方。

你到底想做什么?输出应该是什么样的?


查看完整回答
反对 回复 2021-10-10
  • 2 回答
  • 0 关注
  • 456 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号