Skip to content

Commit 8b497e4

Browse files
m-charltonjorisvandenbossche
authored andcommitted
DOC: astype now takes dict mapping col names to datatypes (#14761) (#14837)
Document feature which was already added in 0.19..0
1 parent 3e4f839 commit 8b497e4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/source/basics.rst

+12
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,7 @@ then the more *general* one will be used as the result of the operation.
17571757
# conversion of dtypes
17581758
df3.astype('float32').dtypes
17591759
1760+
17601761
Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17611762

17621763
.. ipython:: python
@@ -1766,6 +1767,17 @@ Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17661767
dft
17671768
dft.dtypes
17681769
1770+
.. versionadded:: 0.19.0
1771+
1772+
Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFrame.astype`
1773+
1774+
.. ipython:: python
1775+
1776+
dft1 = pd.DataFrame({'a': [1,0,1], 'b': [4,5,6], 'c': [7, 8, 9]})
1777+
dft1 = dft1.astype({'a': np.bool, 'c': np.float64})
1778+
dft1
1779+
dft1.dtypes
1780+
17691781
.. note::
17701782

17711783
When trying to convert a subset of columns to a specified type using :meth:`~DataFrame.astype` and :meth:`~DataFrame.loc`, upcasting occurs.

0 commit comments

Comments
 (0)