Reputation: 7319
I'm just trying to convert a column of numeric strings to ints. This is what I'm trying:
df.date = df.date.astype(np.int64)
But I'm getting the warning:
/Users/austin/anaconda/lib/python3.5/site-packages/pandas/core/generic.py:2773: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self[name] = value
Not sure what this means. I also tried:
df.date = df.date.apply(int)
And I get the same warning as above.
Why doesn't this work and what's the proper way?
Upvotes: 0
Views: 1013
Reputation: 2132
astype
function returns a new array. You need to assign the result:
date = date.astype(int)
Upvotes: 1
Reputation: 164
x = pd.DataFrame(['20.1','19.1','12.3'])
x[0].convert_objects(convert_numeric=True)
Upvotes: 0