0

I have the Zipcode as a column in a dataframe in below format 19678.0 I would like to convert that into int64 19678 When I am trying to run the below code,

call_df['zip']=int(call_df['zip'])

It Says TypeError: cannot convert the series to

Can some one help me with this?

MCN
  • 83
  • 1
  • 7

1 Answers1

0

I believe you're looking for astype():

call_df['zip'] = call_df['zip'].astype(int)

Or if you want to specifically cast to int64, use:

call_df['zip'] = call_df['zip'].astype('int64')
sjw
  • 6,213
  • 2
  • 24
  • 39
  • I have tried the above ,it converted the column to int but still says: 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 – MCN May 01 '18 at 09:32
  • That warning is not related to the issue of type conversion. Most likely you assigned a slice of some other DataFrame to `call_df` when you created it. You can likely silence the warning by chaining `.copy()` to the end of whatever statement you used to create `call_df` in the first place, but it would be better to have a more detailed read on this warning here: https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas – sjw May 01 '18 at 09:40