本文介绍了大 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

类似于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.

您可以检查文档:

类似于 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之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 12:06