How to convert Object to number in pandas?

Asked

Viewed 381 times

-1

import pandas as pd

arq = pd.read_csv("arquivo.csv", sep=";")

I want to use values in the Valor but is in object. But when I use the code arq["Valor"] = arq["Valor"].astype(int) error appears:

Valueerror: invalid literal for int() with base 10: '54.00'

  • Arq["Value"] = Arq["Value"]. astype(int) error appears: Valueerror: invalid literal for int() with base 10: '54.00' But when I change: Arq["Value"] = Arq["Value"]. astype(float) appears the following error: could not Convert string to float: ' 14.170.00'

1 answer

0

What the error is telling you is that Python tried to convert the string "54.00" to int, and failed, even the two houses after the point being zero. You can convert the value column using astype(float) which will transform the values in the "Value" column into an integer with decimal places.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.