.ix()是否总是比.loc()和.iloc()更好,因为它速度更快并且支持整数和标签访问? [英] Is .ix() always better than .loc() and .iloc() since it is faster and supports integer and label access?

查看:65
本文介绍了.ix()是否总是比.loc()和.iloc()更好,因为它速度更快并且支持整数和标签访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Python熊猫库.来自R的背景,索引和选择函数似乎比它们需要的复杂.我的理解是.loc()仅基于标签,而.iloc()仅基于整数.

I'm learning the Python pandas library. Coming from an R background, the indexing and selecting functions seem more complicated than they need to be. My understanding it that .loc() is only label based and .iloc() is only integer based.

如果.ix()更快并且支持整数和标签访问,为什么我应该使用.loc()和.iloc()?

推荐答案

请参考文档

Please refer to the doc Different Choices for Indexing, it states clearly when and why you should use .loc, .iloc over .ix, it's about explicit use case:

.ix支持基于整数和标签的混合访问.主要是 基于标签,但是除非使用标签,否则将退回到整数位置访问 对应的轴是整数类型. .ix是最通用的 将支持.loc和.iloc中的任何输入. .ix还支持 浮点标签方案. .ix在处理时特别有用 具有基于位置和标签的混合层次索引.

.ix supports mixed integer and label based access. It is primarily label based, but will fall back to integer positional access unless the corresponding axis is of integer type. .ix is the most general and will support any of the inputs in .loc and .iloc. .ix also supports floating point label schemes. .ix is exceptionally useful when dealing with mixed positional and label based hierachical indexes.

但是,当轴是基于整数的时,仅基于标签的访问和 不支持位置访问.因此,在这种情况下,通常 最好明确一些,并使用.iloc或.loc.

However, when an axis is integer based, ONLY label based access and not positional access is supported. Thus, in such cases, it’s usually better to be explicit and use .iloc or .loc.

希望这会有所帮助.

感谢@Alexander的评论,熊猫将在 0.20 中弃用ix,详细信息在

Thanks to comment from @Alexander, Pandas is going to deprecate ix in 0.20, details in here.

背后的一个重要原因是因为混合索引-位置和标签(有效使用ix)已成为用户的重要问题来源.

One of the strong reason behind is because mixing indexes -- positional and label (effectively using ix) has been a significant source of problems for users.

预计将迁移为使用ilocloc,这是

It is expected to migrate to use iloc and loc instead, here is a link on how to convert code.

这篇关于.ix()是否总是比.loc()和.iloc()更好,因为它速度更快并且支持整数和标签访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆