Home > database >  Can't remove the comma from price list using df['size_sq.ft'].str.strip(","
Can't remove the comma from price list using df['size_sq.ft'].str.strip(","

Time:08-31

I'm trying to clean 'size_sq.ft' column on a Kaggle dataset (link below) which is an object type.

I have already removed the '$' sign using df['price'].str.strip("$") which is of the same type.

However, I can't seem to do the same for removing the comma (',') from size_sq.ft using df['size_sq.ft'].str.strip(",")

I don't get any errors whatsoever.

My final goal is to convert it into float / int .

Kaggle Kernel link

Dataset link

CodePudding user response:

.str.strip() only operates on leading and trailing characters, if the comma is anywhere else than in first or last position in the string, it won't work. What you are looking for is .str.replace(",", "") which will replace any comma by an empty string.

  • Related