Skip to content

Commit e714d8c

Browse files
committed
Merge branch 'update_docs_astype_with_dict_#14761' of https://github.com/m-charlton/pandas into update_docs_astype_with_dict_#14761
2 parents fddbb2e + 3f5d728 commit e714d8c

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

doc/source/basics.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,12 +1757,14 @@ 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
1761+
17601762
Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`
17611763

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

doc/source/whatsnew/v0.20.0.txt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,15 @@ 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-
.. _whatsnew_0200.enhancements.groupby_access:
47-
48-
Groupby Enhancements
49-
^^^^^^^^^^^^^^^^^^^^
50-
51-
Strings passed to ``DataFrame.groupby()`` as the ``by`` parameter may now reference either column names or index level names (:issue:`5677`)
46+
You can now pass a dictionary mapping column names to desired data types for that
47+
column to :meth:`~DataFrame.astype`.
5248

5349
.. ipython:: python
5450

55-
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
56-
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
57-
58-
index = pd.MultiIndex.from_arrays(arrays, names=['first', 'second'])
59-
60-
df = pd.DataFrame({'A': [1, 1, 1, 1, 2, 2, 3, 3],
61-
'B': np.arange(8)},
62-
index=index)
63-
df
64-
65-
df.groupby(['second', 'A']).sum()
66-
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
6755

6856
.. _whatsnew_0200.enhancements.other:
6957

0 commit comments

Comments
 (0)