I am curious as to why df[2]
is not supported, while df.ix[2]
and df[2:3]
both work.
In [26]: df.ix[2]
Out[26]:
A 1.027680
B 1.514210
C -1.466963
D -0.162339
Name: 2000-01-03 00:00:00
In [27]: df[2:3]
Out[27]:
A B C D
2000-01-03 1.02768 1.51421 -1.466963 -0.162339
I would expect df[2]
to work the same way as df[2:3]
to be consistent with Python indexing convention. Is there a design reason for not supporting indexing row by single integer?
Best Answer
echoing @HYRY, see the new docs in 0.11
http://pandas.pydata.org/pandas-docs/stable/indexing.html
Here we have new operators,
.iloc
to explicity support only integer indexing, and.loc
to explicity support only label indexinge.g. imagine this scenario
[]
slices the rows (by label location) only