对于Series对象(让我们称之为s),pandas提供了三种类型的寻址。
s.iloc [] - 用于整数位置寻址;
s.loc [] - 用于索引标签寻址;和
s.ix [] - 用于整数位置和标签寻址的混合。
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]
所以对于我的问题:是否有指向.ix方法的索引?我错过了一些重要的东西吗?
注意:截至Pandas v0.20,.ix
indexer is deprecated赞成.iloc
/ .loc
。
答案 0 :(得分:19)
注意:截至Pandas v0.20,.ix
indexer is deprecated赞成.iloc
/ .loc
。
对于Series
,.ix
相当于[]
,getitem
语法。 .ix/.loc
支持多轴索引,对于一个系列无关紧要(只有1个轴),因此兼容性。
e.g。
DataFrame(...).ix[row_indexer,column_indexer]
Series(...).ix[row_indexer]
.ix
本身是一种“较旧”的方法,它试图在显示标签或位置(整数)索引时找出您想要的内容。这就是0.11中引入.loc/.iloc
以便用户提供索引选择的原因。