-4

I am trying to convert an object to numeric. But below is the error i have received:

invalid literal for int() with base 10: '106954.64'

I have gone through lots of discussion in the forum, but could not get the logic behind this.

Below is the code:

train['Amount_EUR']=train['Amount_EUR'].astype(int)
Numita
  • 141
  • 8
  • 5
    Well, that's not an integer. Use `float` instead, or `Decimal`. https://docs.python.org/3/library/decimal.html – kaya3 Aug 25 '20 at 10:37
  • Does this answer your question? [How do I parse a string to a float or int?](https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int) – mkrieger1 Aug 25 '20 at 10:38
  • ValueError: could not convert string to float: '#VALUE!' – Numita Aug 25 '20 at 10:42

1 Answers1

0

Try to convert it to a float and then to int:
print(int(float('106954.64')))

Tim Stack
  • 3,209
  • 3
  • 18
  • 39
George
  • 64
  • 6
  • how will i apply the logic as per your advice in a value column as it is a dataframe – Numita Aug 25 '20 at 11:00
  • train['Amount_EUR'].replace('106954.64',int(float('106954.64')),inplace=True)--- i hope this code can work out – Numita Aug 25 '20 at 11:13