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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With