@@ -675,7 +675,8 @@ Advanced Indexing with ``.ix``
675
675
explicit about indexing choices. ``.ix `` allows a great flexibility to specify
676
676
indexing locations by *label * and/or *integer position *. Pandas will attempt
677
677
to use any passed *integer * as *label * locations first (like what ``.loc ``
678
- would do, then to fall back on *positional * indexing, like what ``.iloc `` would do).
678
+ would do, then to fall back on *positional * indexing, like what ``.iloc ``
679
+ would do). See :ref: `Fallback Indexing <indexing.fallback >` for an example.
679
680
680
681
The syntax of using ``.ix `` is identical to ``.loc ``, in :ref: `Selection by Label <indexing.label >`,
681
682
and ``.iloc `` in :ref: `Selection by Position <indexing.integer >`.
@@ -800,6 +801,44 @@ values, though setting arbitrary vectors is not yet supported:
800
801
print df2
801
802
print df2.dtypes
802
803
804
+
805
+ Fallback indexing
806
+ ~~~~~~~~~~~~~~~~~~~~
807
+
808
+ .. _indexing.fallback :
809
+
810
+ Float indexes should be used only with caution. If you have a float indexed
811
+ ``DataFrame `` and try to select using an integer, the row that Pandas returns
812
+ might not be what you expect. Pandas first attempts to use the *integer *
813
+ as a *label * location, but fails to find a match (because the types
814
+ are not equal). Pandas then falls back to back to positional indexing.
815
+
816
+ .. ipython :: python
817
+
818
+ df = pd.DataFrame(np.random.randn(4 ,4 ),
819
+ columns = list (' ABCD' ), index = [1.0 , 2.0 , 3.0 , 4.0 ])
820
+ df
821
+ df.ix[1 ]
822
+
823
+ To select the row you do expect, instead use a float label or
824
+ use ``iloc ``.
825
+
826
+ .. ipython :: python
827
+
828
+ df.ix[1.0 ]
829
+ df.iloc[0 ]
830
+
831
+ Instead of using a float index, it is often better to
832
+ convert to an integer index:
833
+
834
+ .. ipython :: python
835
+
836
+ df_new = df.reset_index()
837
+ df_new[df_new.index == 1.0 ]
838
+ # now you can also do "float selection"
839
+ df_new[(df_new.index >= 1.0 ) & (df_new.index < 2 )]
840
+
841
+
803
842
.. _indexing.class :
804
843
805
844
Index objects
0 commit comments