1

I have a data frame with columns A, B, and C as follows:

df:

A    B    C

1990 1  1,00,000
2000 2  2,00,000
2001 3  3,00,000

I want to convert the column C from object to float. For that, I run the following command:

df["C"].astype(float)

It gives the error:

ValueError: could not convert string to float: '1,00,000'

How do I convert the column to float or int?

ransa
  • 15
  • 8

1 Answers1

1

Try this:

df["C"].str.replace(",", "").astype(float)
Serial Lazer
  • 1,667
  • 1
  • 7
  • 15