http://stackoverflow.com/questions/14035817/slicing-pandas-dataframe-with-negative-index-with-ix-method
In [1]: df = pd.DataFrame(np.random.randn(10, 4))
In [2]: df
Out[2]:
0 1 2 3
0 -3.100926 -0.580586 -1.216032 0.425951
1 -0.264271 -1.091915 -0.602675 0.099971
2 -0.846290 1.363663 -0.382874 0.065783
3 -0.099879 -0.679027 -0.708940 0.138728
4 -0.302597 0.753350 -0.112674 -1.253316
5 -0.213237 -0.467802 0.037350 0.369167
6 0.754915 -0.569134 -0.297824 -0.600527
7 0.644742 0.038862 0.216869 0.294149
8 0.101684 0.784329 0.218221 0.965897
9 -1.482837 -1.325625 1.008795 -0.150439
In [3]: df.ix[-2:]
Out[3]:
0 1 2 3
0 -3.100926 -0.580586 -1.216032 0.425951
1 -0.264271 -1.091915 -0.602675 0.099971
2 -0.846290 1.363663 -0.382874 0.065783
3 -0.099879 -0.679027 -0.708940 0.138728
4 -0.302597 0.753350 -0.112674 -1.253316
5 -0.213237 -0.467802 0.037350 0.369167
6 0.754915 -0.569134 -0.297824 -0.600527
7 0.644742 0.038862 0.216869 0.294149
8 0.101684 0.784329 0.218221 0.965897
9 -1.482837 -1.325625 1.008795 -0.150439
Comment From: wesm
It's a binary-search slicing issue on monotonic indexes. Not sure if will fix. deferring to 0.11 after discussion with @changhiskhan
Comment From: jreback
since ix
transforms neg indicies to pos this won't work..hmm
but the following do
In [4]: df.iloc[-2:]
Out[4]:
0 1 2 3
8 -0.128100 0.033696 0.391006 0.492019
9 0.719473 0.079920 1.710083 -0.291418
In [5]: df[-2:]
Out[5]:
0 1 2 3
8 -0.128100 0.033696 0.391006 0.492019
9 0.719473 0.079920 1.710083 -0.291418
Comment From: jonasrauber
I just ran into this bug. Are you still planning to fix it?
Comment From: jorisvandenbossche
I don't think we will fix this.
As it is actually not a bug. ix
does label-based indexing when having an integer index, so the result you see is correct. If you want integer positional indexing, you can use df.iloc[-2:]
Comment From: jorisvandenbossche
@jreback agree to close?
Comment From: jreback
@jorisvandenbossche yep agreed.