DEV Community

John Higuita
John Higuita

Posted on • Edited on

1 1 1

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay