Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
jreback opened this Issue · 3 comments

2 participants

@jreback
Owner

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

@jreback jreback closed this in #4624
@TomAugspurger
Collaborator

@jreback is this fixed or did you want to raise?

In [10]: df = pd.DataFrame({'A': [1., 2., 3., 4.]})

In [11]: df.dtypes
Out[11]: 
A    float64
dtype: object

In [12]: df.loc[:, 'A'] = df['A'].astype(np.int64)

In [13]: df.dtypes
Out[13]: 
A    float64
dtype: object

In [14]: pd.__version__
Out[14]: '0.13.0rc1-27-g4d5ca5c'

I think this is still the same.

@TomAugspurger
Collaborator

Ah, I guess it's just loc that isn't working. iloc handles the dtype changes fine.

@jreback
Owner

hmm thought all those cases were tested

can u create a new issue pls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.