Skip to content

Commit 3e52718

Browse files
committed
DOC: improve get_dummies dtype documentation
1 parent 1006fa3 commit 3e52718

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

doc/source/whatsnew/v0.22.0.txt

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ Other Enhancements
2424

2525
- Better support for :func:`Dataframe.style.to_excel` output with the ``xlsxwriter`` engine. (:issue:`16149`)
2626
- :func:`pandas.tseries.frequencies.to_offset` now accepts leading '+' signs e.g. '+1h'. (:issue:`18171`)
27-
-
27+
- :func:`pandas.get_dummies` now supports ``dtype`` argument, which forces specific dtype for new columns. (:issue:`18330`)
28+
29+
.. code-block:: ipython
30+
31+
In [1]: df = pd.DataFrame({'a': [1, 2], 'b': [3, 4], 'c': [5, 6]})
32+
In [2]: pd.get_dummies(df, columns=['c'], dtype=bool)
33+
34+
Out[1]:
35+
a b c_5 c_6
36+
0 1 3 True False
37+
1 2 4 False True
2838

2939
.. _whatsnew_0220.api_breaking:
3040

@@ -140,7 +150,7 @@ Sparse
140150
Reshaping
141151
^^^^^^^^^
142152

143-
- :func:`get_dummies` now supports ``dtype`` argument
153+
-
144154
-
145155
-
146156

pandas/core/reshape/reshape.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,14 @@ def get_dummies(data, prefix=None, prefix_sep='_', dummy_na=False,
725725
drop_first : bool, default False
726726
Whether to get k-1 dummies out of k categorical levels by removing the
727727
first level.
728+
729+
.. versionadded:: 0.18.0
730+
728731
dtype : dtype, default np.uint8
729732
Data type to force on a new columns. Only a single dtype is allowed.
730733
731-
.. versionadded:: 0.18.0
734+
.. versionadded:: 0.22.0
735+
732736
Returns
733737
-------
734738
dummies : DataFrame or SparseDataFrame

0 commit comments

Comments
 (0)