python - pandas loc vs. iloc vs. at vs. iat?

最近开始从我的安全位置 (R) 扩展到 Python,并且对 Pandas 中的单元定位/选择感到有些困惑。我已阅读文档,但我很难理解各种本地化/选择选项的实际含义。

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


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

还有,

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

https://stackoverflow.com/questions/28757389/

相关文章:

ruby - 找不到 gem 命令

linux - 选择 Linux I/O 调度程序

python - 如何在不导入的情况下检查 Python 模块是否存在

python - numpy.where() 详细的分步说明/示例

linux - 如何在不重新输入 SSH 密码的情况下执行 `git pull`?

python - ConfigParser 中的列表

android - adb 不显示 nexus 5 设备

python - bs4.FeatureNotFound : Couldn't find a tre

python - 使用Python在SQLite中插入行后如何检索插入的ID?

linux - 什么包包括 AB Ubuntu 中的 Apache 服务器基准测试工具