diff --git a/doc/source/advanced.rst b/doc/source/advanced.rst index 563c869eff54d..b3d5f596f7cdd 100644 --- a/doc/source/advanced.rst +++ b/doc/source/advanced.rst @@ -49,6 +49,11 @@ analysis. See the :ref:`cookbook` for some advanced strategies. +.. versionchanged:: 0.24.0 + + :attr:`MultiIndex.labels` has been renamed to :attr:`MultiIndex.codes` + and :attr:`MultiIndex.set_labels` to :attr:`MultiIndex.set_codes`. + Creating a MultiIndex (hierarchical index) object ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -468,7 +473,7 @@ values across a level. For instance: .. ipython:: python midx = pd.MultiIndex(levels=[['zero', 'one'], ['x','y']], - labels=[[1,1,0,0],[1,0,1,0]]) + codes=[[1,1,0,0],[1,0,1,0]]) df = pd.DataFrame(np.random.randn(4,2), index=midx) df df2 = df.mean(level=0) diff --git a/doc/source/api.rst b/doc/source/api.rst index 81bb420c47a99..a32ba92704e8d 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -1711,7 +1711,7 @@ MultiIndex Attributes MultiIndex.names MultiIndex.levels - MultiIndex.labels + MultiIndex.codes MultiIndex.nlevels MultiIndex.levshape @@ -1722,7 +1722,7 @@ MultiIndex Components :toctree: generated/ MultiIndex.set_levels - MultiIndex.set_labels + MultiIndex.set_codes MultiIndex.to_hierarchical MultiIndex.to_flat_index MultiIndex.to_frame diff --git a/doc/source/dsintro.rst b/doc/source/dsintro.rst index ccd530d11b8f9..2947ca358eab9 100644 --- a/doc/source/dsintro.rst +++ b/doc/source/dsintro.rst @@ -923,7 +923,7 @@ From DataFrame using ``to_panel`` method .. ipython:: python :okwarning: - midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,0,0],[1,0,1,0]]) + midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], codes=[[1,1,0,0],[1,0,1,0]]) df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx) df.to_panel() diff --git a/doc/source/indexing.rst b/doc/source/indexing.rst index 5740ab5fa6921..c430e575a9b5d 100644 --- a/doc/source/indexing.rst +++ b/doc/source/indexing.rst @@ -1571,9 +1571,9 @@ Setting metadata Indexes are "mostly immutable", but it is possible to set and change their metadata, like the index ``name`` (or, for ``MultiIndex``, ``levels`` and -``labels``). +``codes``). -You can use the ``rename``, ``set_names``, ``set_levels``, and ``set_labels`` +You can use the ``rename``, ``set_names``, ``set_levels``, and ``set_codes`` to set these attributes directly. They default to returning a copy; however, you can specify ``inplace=True`` to have the data change in place. @@ -1588,7 +1588,7 @@ See :ref:`Advanced Indexing ` for usage of MultiIndexes. ind.name = "bob" ind -``set_names``, ``set_levels``, and ``set_labels`` also take an optional +``set_names``, ``set_levels``, and ``set_codes`` also take an optional `level`` argument .. ipython:: python diff --git a/doc/source/internals.rst b/doc/source/internals.rst index fce99fc633440..b021797c9ee3f 100644 --- a/doc/source/internals.rst +++ b/doc/source/internals.rst @@ -73,22 +73,22 @@ MultiIndex ~~~~~~~~~~ Internally, the ``MultiIndex`` consists of a few things: the **levels**, the -integer **labels**, and the level **names**: +integer **codes** (until version 0.24 named *labels*), and the level **names**: .. ipython:: python index = pd.MultiIndex.from_product([range(3), ['one', 'two']], names=['first', 'second']) index index.levels - index.labels + index.codes index.names -You can probably guess that the labels determine which unique element is +You can probably guess that the codes determine which unique element is identified with that location at each layer of the index. It's important to -note that sortedness is determined **solely** from the integer labels and does +note that sortedness is determined **solely** from the integer codes and does not check (or care) whether the levels themselves are sorted. Fortunately, the constructors ``from_tuples`` and ``from_arrays`` ensure that this is true, but -if you compute the levels and labels yourself, please be careful. +if you compute the levels and codes yourself, please be careful. Values ~~~~~~ diff --git a/doc/source/io.rst b/doc/source/io.rst index 92fc28af0281a..398a234b817b0 100644 --- a/doc/source/io.rst +++ b/doc/source/io.rst @@ -3685,8 +3685,8 @@ storing/selecting from homogeneous index ``DataFrames``. index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two', 'three']], - labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], - [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], + codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], + [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], names=['foo', 'bar']) df_mi = pd.DataFrame(np.random.randn(10, 3), index=index, columns=['A', 'B', 'C'])