问题
I have a problem with a pandas Dataframe that amongst other things contains the number of rooms in an apartment (type String).
This data consists of a unicode character u"\u00BD" (https://www.fileformat.info/info/unicode/char/00bd/index.htm).
How do i effectively replace this character with decimal values so that instead of the unicode character the data will read 2.5, 3.5, 4.5 etc (Still String format)
.
It currently looks like this: 2½, 3½, 4½ etc
And i want the values in the column to be 2.5, 3.5, 4.5 etc
.
回答1:
You can fix your column with:
df['rooms'] = df['rooms'].str.replace("½", ".5")
To make it a float:
df['rooms'] = df['rooms'].str.replace("½", ".5").apply(float)
来源:https://stackoverflow.com/questions/49465836/replacing-unicode-character-in-pandas-dataframe-column