大 pandas .iloc和.iat之间的区别? [英] Difference between pandas .iloc and .iat?

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

问题描述

我最近注意到,使用.iloc遍历DataFrame行的函数非常慢.我发现有一个叫做.iat的更快的方法,据说等效于.iloc.我尝试了一下,将运行时间减少了约75%.

I've recently noticed that a function where I iterate over a DataFrame rows using .iloc is very slow. I found out that there's a faster method called .iat, that's said to be equivalent to .iloc. I tried it and it cut the run time down by about 75%.

但是我有点犹豫:为什么有一种更快的等效"方法?两者的内部运作方式之间一定存在差异,并且它们之所以存在,而不仅仅是更快的原因,两者之间必须存在差异.我尝试到处寻找,但即使熊猫文档也指出了这一点

But I'm a little hesitant: why is there an "equivalent" method that's faster? There must be some difference between the inner workings of these two and a reason why they both exist and not just the faster one. I've tried looking everywhere but even the pandas documentation just states that

DataFrame.iat
快速整数位置标量访问器.

DataFrame.iat
Fast integer location scalar accessor.

类似于iloc,iat提供基于整数的查找.您也可以使用这些索引器进行设置.

Similarly to iloc, iat provides integer based lookups. You can also set using these indexers.

那无济于事.

使用.iat是否有限制?为什么更快?更草率?还是我只是转而使用.iat并高兴地忘记了.iloc曾经存在过?

Are there limits to using .iat? Why is faster; is it sloppier? Or do I just switch to using .iat and happily forget .iloc ever existed?

推荐答案

iatat仅使用标量,因此非常快.较慢的,更通用的功能是ilocloc.

iat and at working with scalar only, so very fast. Slower, more general functions are iloc and loc.

您可以检查文档:

由于使用 [] 进行索引必须处理很多情况(单标签访问,切片,布尔索引等),因此要弄清楚您要使用的内容会产生一些开销重新要求.如果只想访问标量值,最快的方法是使用在所有数据结构上实现的 at iat 方法.

Since indexing with [] must handle a lot of cases (single-label access, slicing, boolean indexing, etc.), it has a bit of overhead in order to figure out what you’re asking for. If you only want to access a scalar value, the fastest way is to use the at and iat methods, which are implemented on all of the data structures.

类似于 loc ,at提供基于标签的标量查找,而 iat 提供类似于 iloc 的基于整数的查找.

Similarly to loc, at provides label based scalar lookups, while, iat provides integer based lookups analogously to iloc.

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

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