Skip to content

Commit b9414a9

Browse files
committed
Correcting after review
Ability to pass dict mapping column to dtype introduced in v0.19 not v0.20
1 parent bc65ff4 commit b9414a9

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

doc/source/basics.rst

+12-14
Original file line numberDiff line numberDiff line change
@@ -1757,17 +1757,27 @@ 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-
.. versionadded:: 0.20.0
17611760
17621761
Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17631762

17641763
.. ipython:: python
17651764
17661765
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
1767-
dft = dft.astype({'a': np.float64, 'c': np.uint8})
1766+
dft[['a','b']] = dft[['a','b']].astype(np.uint8)
17681767
dft
17691768
dft.dtypes
17701769
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+
17711781
.. note::
17721782

17731783
When trying to convert a subset of columns to a specified type using :meth:`~DataFrame.astype` and :meth:`~DataFrame.loc`, upcasting occurs.
@@ -1781,18 +1791,6 @@ Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17811791
dft.loc[:, ['a', 'b']] = dft.loc[:, ['a', 'b']].astype(np.uint8)
17821792
dft.dtypes
17831793
1784-
1785-
.. versionadded:: 0.19
1786-
1787-
Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFrame.astype`
1788-
1789-
.. ipython:: python
1790-
1791-
dft1 = pd.DataFrame({'a': [1,0,1], 'b': [4,5,6], 'c': [7, 8, 9]})
1792-
dft1 = dft1.astype({'a': np.bool, 'c': np.float64})
1793-
dft1
1794-
dft1.dtypes
1795-
17961794
.. _basics.object_conversion:
17971795

17981796
object conversion

0 commit comments

Comments
 (0)