中国统计网|Python拍了拍你,一份【同时选择行列方法】的盘点送给你( 二 )
-- 输出报错: #报错:英:IndexError: .iloc requires numeric indexers, got ['name''age'];汉:iloc需要数字索引器 , 得到['name''age'] #原因分析:当使用行(列)名称索引时 , 不能使用iloc方法;若使用iloc , 必须要求行或列都严格使用数字或者切片进行索引; #报错:英:TypeError: cannotdoslice indexing on <class'pandas.core.indexes.base.Index'> with these indexers [0] of <class'int'> / 中:TypeError:无法使用<class'int'>的这些索引器[0]在<class>上进行切片索引 #报错:英:AttributeError:“ DataFrame”对象没有属性“ ix”;/汉:AttributeError:“ DataFrame”对象没有属性“ ix” #原因分析:新版本的anconda目前已经不支持"ix"了!方式四位置索引 + 位置索引选择指定行和列# 位置索引:选择第1,4行 , 第1,3列 s.iloc[[0,3],[0,2]] --输出结果: nameage A1qinlu 18 A4junjun 25 # case1:索引超出 s.iloc[[1,2],[2,3]] # 报错:IndexError: positional indexers are out-of-bounds/汉:IndexError:位置索引器超出范围; # case2:s.loc[[0,3],[0,2]] # 报错:KeyError: "None of [Int64Index([0, 3], dtype='int64')] are in the [index]"/ 中文:KeyError:“ [Int64Index([0 , 3] , dtype ='int64')]都不在[索引]中” # 原因分析:当使用位置索引 + 位置索引选择指定行和列时 , 需要利用iloc方法传入行列位置方式五普通索引 + 普通索引选择指定行和列# 普通索引 + 普通索引就是通过同时传入行和列的索引名称进行数据选择 , 需要用到loc方法; s.loc[['A1','A2','A4'],['name','age']] -- 输出结果: name age A1 qinlu18 A2 lulu19 A4 junjun 25 # 报错:s.iloc[['A1','A2','A4'],['name','age']];英文:IndexError: .iloc requires numeric indexers, got ['A1''A2''A4']End.
作者:爱数据小辉
本文为中国统计网原创 , 转载请联系后台
推荐阅读
- 中年|中国-东盟区块链应用创新实验室揭牌
- IT爆料猿|中国电信6月5G用户数净增779万户,累计3784万
- 2020|影谱科技入选“2020中国AI商业落地价值潜力100强榜单”
- 中国航务周刊|港航业再现跨界收购!
- 招生|有道词典与中国教育在线合作,开通“高考招生”直播服务
- CSDN|由 Apache 说开,中国开源项目已经走向世界!
- AI财经社|谷歌云为何“放弃”中国市场?有人为它算了账,投入产出比太低
- 网速|全球网速排名:中国手机网速世界第三,美国第34
- 驱动中国|国内首次应用!支付宝开放宠物鼻纹识别技术:猫狗都能买保险
- 魅族|2020年BrandZ中国全球化品牌50强新鲜出炉,魅族再上榜,位列34名
