Python pandas 系列的 .ix 索引有什么意义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20838395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:20:17  来源:igfitidea点击:

What is the point of .ix indexing for pandas Series

pythonpandas

提问by Mark Graph

For the Series object (let's call it s), pandas offers three types of addressing.

对于 Series 对象(我们称之为 s),pandas 提供了三种寻址方式。

s.iloc[] -- for integer position addressing;

s.iloc[]——用于整数位置寻址;

s.loc[] -- for index label addressing; and

s.loc[]——用于索引标签寻址;和

s.ix[] -- for a hybrid of integer position and label addressing.

s.ix[]——用于整数位置和标签寻址的混合。

The pandas object also performs ix addressing directly.

pandas 对象也直接执行 ix 寻址。

# play data ...
import string
idx = [i for i in string.uppercase] # A, B, C .. Z
t = pd.Series(range(26), index=idx) # 0, 1, 2 .. 25

# examples ...
t[0]              # --> 0
t['A']            # --> 0
t[['A','M']]      # --> [0, 12]
t['A':'D']        # --> [0, 1, 2, 3]
t.iloc[25]        # --> 25
t.loc['Z']        # --> 25
t.loc[['A','Z']]  # --> [0, 25]
t.ix['A':'C']     # --> [0, 1, 2]
t.ix[0:2]         # --> [0, 1]

So to my question: is there a point to the .ix method of indexing? Am I missing something important here?

所以我的问题是: .ix 索引方法有什么意义吗?我在这里遗漏了什么重要的东西吗?

Note: As of Pandas v0.20, .ixindexer is deprecatedin favour of .iloc/ .loc.

注意:从 Pandas v0.20 开始,.ix索引器已被弃用,取而代之的是.iloc/ .loc

采纳答案by Jeff

Note: As of Pandas v0.20, .ixindexer is deprecatedin favour of .iloc/ .loc.

注意:从 Pandas v0.20 开始,.ix索引器已被弃用,取而代之的是.iloc/ .loc

For a Series, .ixis equivalent of [], the getitemsyntax. .ix/.locsupport multi-axis indexing, which for a Series does not matter (only has 1 axis), and hence is there for compatibility.

对于 a Series.ix相当于[]getitem语法。.ix/.loc支持多轴索引,这对于系列来说无关紧要(只有 1 个轴),因此是为了兼容性。

e.g.

例如

DataFrame(...).ix[row_indexer,column_indexer]
Series(...).ix[row_indexer]

.ixitself is an 'older' method that tries to figure out what you want when presented with label or positional (integer) indexing. This is why .loc/.ilocwere introduced in 0.11 to provide indexing choice by the user.

.ix本身是一种“较旧”的方法,它试图在显示标签或位置(整数)索引时找出您想要的内容。这就是为什么.loc/.iloc在 0.11 中引入以提供用户索引选择的原因。