Skip to content

BUG: astype assignment via iloc/loc not working #4312

Closed
@jreback

Description

@jreback

http://stackoverflow.com/questions/17778139/pandas-unable-to-change-column-data-type/17778560#17778560

This might be trying to coerce object dtype to a real dtype (int/float) and is failing
Should prob raise for now (or work). Not working with iloc/loc.

In [66]: df = DataFrame([['1','2','3','.4',5,6.,'foo']],columns=list('ABCDEFG'))

In [67]: df.dtypes
Out[67]: 
A     object
B     object
C     object
D     object
E      int64
F    float64
G     object
dtype: object

In [68]: df.iloc[:,0:3] = df.iloc[:,0:3].astype(int)

In [69]: df.dtypes
Out[69]: 
A     object
B     object
C     object
D     object
E      int64
F    float64
G     object
dtype: object

In [70]: df.iloc[:,0:3] = df.iloc[:,0:3].convert_objects(convert_numeric=True)

In [71]: df.dtypes
Out[71]: 
A     object
B     object
C     object
D     object
E      int64
F    float64
G     object
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions