首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法显示dataframe的列

无法显示dataframe的列
EN

Stack Overflow用户
提问于 2021-08-21 10:29:51
回答 2查看 5.5K关注 0票数 0

当我试图打印数据集中的一列时,它显示了错误。

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(自、键、方法、容忍) 2645尝试:-> 2646返回self._engine.get_loc( key ) 2647 ( 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.PyObjectHashTable.get_item()中的pandas_libs\hashtable_class_helper.pxi

pandas._libs.hashtable.PyObjectHashTable.get_item()中的pandas_libs\hashtable_class_helper.pxi

KeyError:“标签”

在处理上述异常的过程中,发生了另一个异常:

KeyError跟踪(最近一次调用)在->1个数据“‘Label”中

~\anaconda3\lib\site-packages\pandas\core\frame.py in getitem(self,key) 2798如果self.columns.nlevels > 1: 2799返回self._getitem_multilevel(键) -> 2800索引器=self.columns.get_loc(键) 2801 if is_integer(索引器):2802索引器=索引器

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(自、键、方法、公差) 2646返回self._engine.get_loc( key ) 2647 (KeyError除外:-> 2648返回self._engine.get_loc(self._maybe_cast_indexer(key)) 2649 )

indexer = self.get_indexer(key,method=method,tolerance=tolerance) 2650,如果indexer.ndim >1或indexer.size > 1:

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.PyObjectHashTable.get_item()中的pandas_libs\hashtable_class_helper.pxi

pandas._libs.hashtable.PyObjectHashTable.get_item()中的pandas_libs\hashtable_class_helper.pxi

KeyError:“标签”

代码语言:javascript
运行
复制
data['Label']

EN

Stack Overflow用户

回答已采纳

发布于 2021-08-21 10:41:25

有可能列名有尾随空格。只需尝试打印列名&验证。

print(data.columns)

或者尝试在后面打印列。

data.columns = data.columns.str.strip()

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68872184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档