You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/user_guide/reshaping.rst
+10-1Lines changed: 10 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -606,7 +606,7 @@ This function is often used along with discretization functions like ``cut``:
606
606
607
607
pd.get_dummies(pd.cut(values, bins))
608
608
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>`.
610
610
611
611
:func:`get_dummies` also accepts a ``DataFrame``. By default all categorical
612
612
variables (categorical in the statistical sense, those with `object` or
@@ -679,6 +679,15 @@ To choose another dtype, use the ``dtype`` argument:
679
679
680
680
pd.get_dummies(df, dtype=bool).dtypes
681
681
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.
0 commit comments