@@ -661,14 +661,18 @@ values NOT in the categories, similarly to how you can reindex ANY pandas index.
661
661
Reshaping and Comparision operations on a ``CategoricalIndex `` must have the same categories
662
662
or a ``TypeError `` will be raised.
663
663
664
- .. ipython :: python
665
- :okexcept:
664
+ .. code-block :: python
665
+
666
+ In [9 ]: df3 = pd.DataFrame({' A' : np.arange(6 ),
667
+ ' B' : pd.Series(list (' aabbca' )).astype(' category' )})
668
+
669
+ In [11 ]: df3 = df3.set_index(' B' )
670
+
671
+ In [11 ]: df3.index
672
+ Out[11 ]: CategoricalIndex([u ' a' , u ' a' , u ' b' , u ' b' , u ' c' , u ' a' ], categories = [u ' a' , u ' b' , u ' c' ], ordered = False , name = u ' B' , dtype = ' category' )
666
673
667
- df3 = pd.DataFrame({' A' : np.arange(6 ),
668
- ' B' : pd.Series(list (' aabbca' )).astype(' category' )})
669
- df3 = df3.set_index(' B' )
670
- df3.index
671
- pd.concat([df2, df3]
674
+ In [12 ]: pd.concat([df2, df3]
675
+ TypeError : categories must match existing categories when appending
672
676
673
677
.. _indexing.float64index:
674
678
@@ -734,18 +738,20 @@ In float indexes, slicing using floats is allowed
734
738
735
739
In non- float indexes, slicing using floats will raise a `` TypeError ``
736
740
737
- .. ipython:: python
738
- :okexcept:
741
+ .. code- block:: python
742
+
743
+ In [1 ]: pd.Series(range (5 ))[3.5 ]
744
+ TypeError : the label [3.5 ] is not a proper indexer for this index type (Int64Index)
739
745
740
- pd.Series(range (5 ))[3.5 ]
741
- pd.Series( range ( 5 )) [3.5 : 4.5 ]
746
+ In [ 1 ]: pd.Series(range (5 ))[3.5 : 4 .5 ]
747
+ TypeError : the slice start [3.5 ] is not a proper indexer for this index type (Int64Index)
742
748
743
749
Using a scalar float indexer will be deprecated in a future version, but is allowed for now.
744
750
745
- .. ipython:: python
746
- :okwarning:
751
+ .. code- block:: python
747
752
748
- pd.Series(range (5 ))[3.0 ]
753
+ In [3 ]: pd.Series(range (5 ))[3.0 ]
754
+ Out[3 ]: 3
749
755
750
756
Here is a typical use- case for using this type of indexing. Imagine that you have a somewhat
751
757
irregular timedelta- like indexing scheme, but the data is recorded as floats. This could for
0 commit comments