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

Mar*_*aph 18 python pandas

对于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中引入以提供用户索引选择的原因.

  • 对于整数索引,`.ix`和`[]`不完全相同.例如`s [0:3]`取决于第二项(基于位置的逻辑),而`s.ix [0:3]`包括第三项(基于标签的逻辑). (11认同)