Skip to content

Commit 278e922

Browse files
committed
DOC: Some cleaning up
1 parent e1877bf commit 278e922

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

doc/source/basics.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -1730,23 +1730,23 @@ Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17301730

17311731
.. ipython:: python
17321732
1733-
df = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
1734-
df[['a','b']] = df[['a','b']].astype(np.uint8)
1735-
df
1736-
df.dtypes
1733+
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
1734+
dft[['a','b']] = dft[['a','b']].astype(np.uint8)
1735+
dft
1736+
dft.dtypes
17371737
17381738
.. note::
17391739

17401740
When trying to convert a subset of columns to a specified type using :meth:`~DataFrame.astype` and :meth:`~DataFrame.loc`, utilizing **:** as mask, upcasting occurs.
17411741

1742-
:meth:`~DataFrame.loc` tries to fit in what we are assigning to the current dtypes, while [ ] will overwrite them taking the dtype from the right hand side. Therefore the following piece of code produces the unintended result.
1742+
:meth:`~DataFrame.loc` tries to fit in what we are assigning to the current dtypes, while ``[]`` will overwrite them taking the dtype from the right hand side. Therefore the following piece of code produces the unintended result.
17431743

17441744
.. ipython:: python
17451745
1746-
df = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
1747-
df.loc[:, ['a', 'b']].astype(np.uint8).dtypes
1748-
df.loc[:, ['a', 'b']] = df.loc[:, ['a', 'b']].astype(np.uint8)
1749-
df.dtypes
1746+
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
1747+
dft.loc[:, ['a', 'b']].astype(np.uint8).dtypes
1748+
dft.loc[:, ['a', 'b']] = dft.loc[:, ['a', 'b']].astype(np.uint8)
1749+
dft.dtypes
17501750
17511751
object conversion
17521752
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)