DEV Community

John Higuita
John Higuita

Posted on • Updated on

Change column type in pandas to numeric (particular case)

Alt Text

to convert the columns to numeric types, you have four main options:

  1. to_numeric()
  2. astype()
  3. infer_objects()
  4. convert_dtypes()

however, none of the four works in this case because each value has a thousands separator with a comma and a decimal separator with a dot, so this causes error.

You must delete the comma and then you can convert it to numeric.

df[column].str.replace(",", "").astype(float)

Top comments (0)