Skip to content

Commit 3f5d728

Browse files
committed
astype method now takes dict mapping col names to datatypes pandas-dev#14761
Updating documentation to reflect change
1 parent 2466ecb commit 3f5d728

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

doc/source/basics.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -1755,12 +1755,14 @@ then the more *general* one will be used as the result of the operation.
17551755
# conversion of dtypes
17561756
df3.astype('float32').dtypes
17571757
1758+
.. versionadded:: 0.20.0
1759+
17581760
Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17591761

17601762
.. ipython:: python
17611763
17621764
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
1763-
dft[['a','b']] = dft[['a','b']].astype(np.uint8)
1765+
dft = dft.astype({'a': np.float64, 'c': np.uint8})
17641766
dft
17651767
dft.dtypes
17661768

doc/source/whatsnew/v0.20.0.txt

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ fixed-width text files, and :func:`read_excel` for parsing Excel files.
4343
pd.read_fwf(StringIO(data)).dtypes
4444
pd.read_fwf(StringIO(data), dtype={'a':'float64', 'b':'object'}).dtypes
4545

46+
You can now pass a dictionary mapping column names to desired data types for that
47+
column to :meth:`~DataFrame.astype`.
48+
49+
.. ipython:: python
50+
51+
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
52+
dft = dft.astype({'a': np.float64, 'c': np.uint8})
53+
dft
54+
dft.dtypes
55+
4656
.. _whatsnew_0200.enhancements.other:
4757

4858
Other enhancements

0 commit comments

Comments
 (0)