I have a dataframe in pandas which I would like to remove fractions from the column with addresses. I can't figure out the correct regress implementation to remove them.
The sample addresses look like:
580 1/4 Broadway Street
85 1/4 Grand Street
Two things, I'm not sure how to loop through the dataframe to remove the special characters.
And two what is the correct regex function and how do I regroup the flags?
I came up with
"^(. )\\d+/\\d+\\s(. )" and "\\1\\2" to group the flags together
Or is there just a better way to do this?
Use str.replace
, you don't need matching groups at all.
df.address.str.replace(r'\d+\/\d+', '')
0 580 Broadway Street
1 85 Grand Street
Name: address, dtype: object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.