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?

1
  • Its just me or the commas placed on the wrong place.. Commented Nov 17, 2020 at 7:10

1 Answer 1

1

Try this:

df["C"].str.replace(",", "").astype(float)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.