Skip to content

Commit 6a408ea

Browse files
committed
Reference get_dummies/ from_dummies in reshaping docs
1 parent 1e0b526 commit 6a408ea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

doc/source/user_guide/reshaping.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ This function is often used along with discretization functions like ``cut``:
606606
607607
pd.get_dummies(pd.cut(values, bins))
608608
609-
See also :func:`Series.str.get_dummies <pandas.Series.str.get_dummies>`.
609+
See also :func:`Series.str.get_dummies <pandas.Series.str.get_dummies>` and :func:`Categorical.get_dummies <pandas.Categorical.get_dummies>`.
610610

611611
:func:`get_dummies` also accepts a ``DataFrame``. By default all categorical
612612
variables (categorical in the statistical sense, those with `object` or
@@ -679,6 +679,15 @@ To choose another dtype, use the ``dtype`` argument:
679679
680680
pd.get_dummies(df, dtype=bool).dtypes
681681
682+
A :class:`~pandas.Categorical` can be recovered from a :class:`~pandas.DataFrame` of such dummy variables using :meth:`~pandas.Categorical.from_dummies`.
683+
Use the ``prefix`` and ``prefix_sep`` arguments to select and rename columns which have had a prefix applied in the same way as :class:`~pandas.get_dummies` does.
684+
685+
.. ipython:: python
686+
687+
df = pd.get_dummies(list("abca"))
688+
689+
pd.Categorical.from_dummies(df)
690+
682691
683692
.. _reshaping.factorize:
684693

0 commit comments

Comments
 (0)