Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of .ix indexing for pandas Series

Tags:

python

pandas

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

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

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

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

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]

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

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

like image 800
Mark Graph Avatar asked Dec 30 '13 11:12

Mark Graph


1 Answers

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

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.

e.g.

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

.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.

like image 108
Jeff Avatar answered Nov 13 '22 03:11

Jeff