pandas loc vs. iloc vs. ix vs. at vs. iat? [英] pandas loc vs. iloc vs. ix 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.
- 有没有理由我应该在最普通的选项
.ix
上使用.loc
或.iloc
? - 我了解到
.loc
,iloc
,at
和iat
可能提供了.ix
无法提供的某些保证的正确性,但我也阅读了.ix
往往是全面最快的解决方案. - 请解释使用除
.ix
以外的任何东西的真实世界的最佳实践推理吗?
- Is there a reason why I should ever use
.loc
or.iloc
over the most general option.ix
? - I understand that
.loc
,iloc
,at
, andiat
may provide some guaranteed correctness that.ix
can't offer, but I've also read where.ix
tends to be the fastest solution across the board. - Please explain the real-world, best-practices reasoning behind utilizing anything other than
.ix
?
推荐答案
loc:仅适用于索引
iloc:在位置上进行工作
ix:您可以从数据框中获取数据,而不必将其包含在索引中
at :获取标量值.这是一个非常快速的位置
iat :获取标量值.这是一个非常快的iloc
loc: only work on index
iloc: work on position
ix: You can get data from dataframe without it being in the index
at: get scalar values. It's a very fast loc
iat: Get scalar values. It's a very fast iloc
http://pyciencia. blogspot.com/2015/05/obtener-y-filtrar-datos-de-un-dataframe.html
Note: As of pandas 0.20.0
, the .ix
indexer is deprecated in favour of the more strict .iloc
and .loc
indexers.
这篇关于pandas loc vs. iloc vs. ix vs. at vs. iat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!