Skip to content

Commit

Permalink
DOC: astype now takes dict mapping col names to datatypes (#14761) (#…
Browse files Browse the repository at this point in the history
…14837)

Document feature which was already added in 0.19..0
  • Loading branch information
m-charlton authored and jorisvandenbossche committed Dec 22, 2016
1 parent 3e4f839 commit 8b497e4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,7 @@ then the more *general* one will be used as the result of the operation.
# conversion of dtypes
df3.astype('float32').dtypes
Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`

.. ipython:: python
Expand All @@ -1766,6 +1767,17 @@ Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
dft
dft.dtypes
.. versionadded:: 0.19.0

Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFrame.astype`

.. ipython:: python
dft1 = pd.DataFrame({'a': [1,0,1], 'b': [4,5,6], 'c': [7, 8, 9]})
dft1 = dft1.astype({'a': np.bool, 'c': np.float64})
dft1
dft1.dtypes
.. note::

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

0 comments on commit 8b497e4

Please sign in to comment.