栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

panda使用中的报错 loc iloc ix cannot do slice indexing on Index with these indexers [2] of type int

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

panda使用中的报错 loc iloc ix cannot do slice indexing on Index with these indexers [2] of type int

cannot do slice indexing on Index with these indexers [2] of type int
model.fit(trainSet.loc[:,2:6],trainSet.loc[:,-1])

使用python的库panda时报了这样的错,原因是使用代码时直接把ix改成了loc(因为现在版本里好像没有ix了)
错误原因: iloc主要使用数字来索引数据,而不能使用字符型的标签来索引数据。而loc则刚好相反,只能使用字符型标签来索引数据,不能使用数字来索引数据,不过有特殊情况,当数据框dataframe的行标签或者列标签为数字,loc就可以来其来索引。
解决方法:报错的地方把loc改成iloc

参考文章:参考文章

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/715059.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号