本文介绍了.ix为 pandas 系列建立索引的意义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

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

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

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

pandas对象还直接执行ix寻址.

The pandas object also performs ix addressing directly.

# 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索引编制方法是否有意义?我在这里错过了重要的东西吗?

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

注意:从Pandas v0.20开始,.ix 不推荐使用索引器,而推荐使用.iloc/.loc.

Note: As of Pandas v0.20, .ix indexer is deprecated in favour of .iloc / .loc.

推荐答案

注意:从Pandas v0.20开始,.ix 不推荐使用索引器,而推荐使用.iloc/.loc.

Note: As of Pandas v0.20, .ix indexer is deprecated in favour of .iloc / .loc.

对于Series.ix等效于[](getitem语法). .ix/.loc支持多轴分度,对于系列而言,这无关紧要(仅具有1个轴),因此具有兼容性.

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

例如

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

.ix本身是一个较旧的"方法,当使用标签或位置(整数)索引显示时,它会尝试弄清您想要的内容.这就是为什么在.loc/.iloc来为用户提供索引选择的原因.

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

这篇关于.ix为 pandas 系列建立索引的意义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:24