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