pandas loc vs. iloc vs. at vs. iat? [英] pandas loc vs. iloc vs. at vs. iat?

查看:106
本文介绍了pandas loc vs. iloc vs. at vs. iat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近开始从我的安全地方(R)分支到Python,并且对 Pandas 中的单元格定位/选择有些困惑.我已经阅读了文档,但仍在努力了解各种本地化/选择选项的实际含义.

Recently began branching out from my safe place (R) into Python and and am a bit confused by the cell localization/selection in Pandas. I've read the documentation but I'm struggling to understand the practical implications of the various localization/selection options.

我是否有理由在 at iat 上使用 .loc .iloc 或相反亦然?在什么情况下应该使用哪种方法?

Is there a reason why I should ever use .loc or .iloc over at, and iat or vice versa? In what situations should I use which method?

注意:将来的读者应该知道,这个问题是古老的,是在以前存在名为 .ix 的函数的pandas v0.20之前编写的.此方法后来被分为两个代码- loc iloc -以便在基于位置的索引和基于标签的索引之间进行显式区分.请注意, ix 因行为不一致且难以理解而中断,并且在当前版本的熊猫(> = 1.0)中不再存在.

Note: future readers be aware that this question is old and was written before pandas v0.20 when there used to exist a function called .ix. This method was later split into two - loc and iloc - to make the explicit distinction between positional and label based indexing. Please beware that ix was discontinued due to inconsistent behavior and being hard to grok, and no longer exists in current versions of pandas (>= 1.0).

推荐答案

loc:仅适用于索引
iloc:在位置上进行工作
at :获取标量值.这是一个非常快速的位置
iat :获取标量值.这是一个非常快的iloc

loc: only work on index
iloc: work on position
at: get scalar values. It's a very fast loc
iat: Get scalar values. It's a very fast iloc

at iat 用于访问标量,即单个元素在数据框中,而 loc iloc 是访问多个元素同时进行,有可能执行矢量化操作.

at and iat are meant to access a scalar, that is, a single element in the dataframe, while loc and iloc are ments to access several elements at the same time, potentially to perform vectorized operations.

http://pyciencia.blogspot.com/2015/05/obtener-y-filtrar-datos-de-un-dataframe.html

这篇关于pandas loc vs. iloc vs. at vs. iat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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