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

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

Closed
jreback opened this issue Jul 22, 2013 · 3 comments · Fixed by #4624

Comments

@jreback
Copy link
Contributor

commented Jul 22, 2013

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

@TomAugspurger

This comment has been minimized.

Copy link
Contributor

commented Dec 15, 2013

@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

This comment has been minimized.

Copy link
Contributor

commented Dec 15, 2013

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

@jreback

This comment has been minimized.

Copy link
Contributor Author

commented Dec 15, 2013

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
Projects
None yet
2 participants
You can’t perform that action at this time.