对于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]
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:有没有指向.ix方法的索引?我错过了一些重要的东西吗?
注:由于熊猫v0.20中,.ix 索引器已被弃用赞成.iloc/ .loc.
Jef*_*eff 19
注:由于熊猫v0.20中,.ix 索引器已被弃用赞成.iloc/ .loc.
对于a Series,.ix等同[]于getitem语法..ix/.loc支持多轴索引,对于系列无关紧要(只有1轴),因此兼容性.
例如
DataFrame(...).ix[row_indexer,column_indexer]
Series(...).ix[row_indexer]
Run Code Online (Sandbox Code Playgroud)
.ix本身是一种"较旧"的方法,试图在提供标签或位置(整数)索引时找出你想要的东西.这就是为什么.loc/.iloc在0.11中引入以提供用户索引选择的原因.