Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: update docs for .astype with dict #14761

Closed
jreback opened this issue Nov 29, 2016 · 1 comment
Closed

DOC: update docs for .astype with dict #14761

jreback opened this issue Nov 29, 2016 · 1 comment
Labels
Docs Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Nov 29, 2016

in #13375 added dict argument to .astype

need to add a doc examp:

http://pandas.pydata.org/pandas-docs/stable/basics.html#

add versionadded tag to .astype docstring (0.19.0)

@jreback jreback added Difficulty Novice Docs Dtype Conversions Unexpected or buggy dtype conversions labels Nov 29, 2016
@jreback jreback added this to the Next Major Release milestone Nov 29, 2016
@m-charlton
Copy link
Contributor

I'm willing to do this. I'm assuming that the next major release is 0.20.0. If
so the files that need changing are

docs/source/basics.rst
docs/source/whatsnew/v0.20.0.txt

I intend to replace the existing section see

Convert a subset of columns to a specified type using astype()

In [318]: dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})

In [319]: dft[['a','b']] = dft[['a','b']].astype(np.uint8)

In [320]: dft
Out[320]: 
   a  b  c
0  1  4  7
1  2  5  8
2  3  6  9

In [321]: dft.dtypes
Out[321]: 
a    uint8
b    uint8
c    int64
dtype: object

With the following:

Convert a subset of columns to a specified type by passing a dictionary,
mapping the column name to the type for that column, to astype()

In [318]: dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})

In [319]: dft = dft.astype({'a':np.float64, 'c': np.uint8})

In [320]: dft
Out[320]: 
     a  b  c
0  1.0  4  7
1  2.0  5  8
2  3.0  6  9

In [321]: dft.dtypes
Out[321]: 
a    float64
b      int64
c      uint8
dtype: object

Just to confirm, this enhancement maps a column name to a desired data type for
that column. The original text mentioned a column index, If I use an index, I
get a KeyError.

Cheers

Michael.

m-charlton added a commit to m-charlton/pandas that referenced this issue Dec 9, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 16, 2016
jorisvandenbossche pushed a commit that referenced this issue Dec 22, 2016
ShaharBental pushed a commit to ShaharBental/pandas that referenced this issue Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

No branches or pull requests

2 participants