pandas -从序列的字符串开头删除数字 [英] Pandas - remove numbers from start of string in series
问题描述
我有一系列地址,想要一个只带街道名称的地址.唯一要注意的是,有些地址没有门牌号,有些则没有.
I've got a series of addresses and would like a series with just the street name. The only catch is some of the addresses don't have a house number, and some do.
所以,如果我有一个看起来像这样的系列:
So if I have a series that looks like:
Idx
0 11000 SOUTH PARK
1 20314 BRAKER LANE
2 203 3RD ST
3 BIRMINGHAM PARK
4 E 12TH
我要写什么函数来获得
Idx
0 SOUTH PARK
1 BRAKER LANE
2 3RD ST
3 BIRMINGHAM PARK
4 E 12TH
在字符串的开头删除了完全由数字字符组成的所有单词"吗?如您在上面看到的,我想保留"3RD STREET"开头的3.我在想一个正则表达式,但这超出了我的范围.谢谢!
where any 'words' made entirely of numeric characters at the beginning of the string have been removed? As you can see above, I would like to retain the 3 that '3RD STREET' starts with. I'm thinking a regular expression but this is beyond me. Thanks!
推荐答案
您可以将str.replace
与正则表达式 ^ \ d + \ s + 一起使用以删除前导数字:
You can use str.replace
with regex ^\d+\s+ to remove leading digits:
s.str.replace('^\d+\s+', '')
Out[491]:
0 SOUTH PARK
1 BRAKER LANE
2 3RD ST
3 BIRMINGHAM PARK
4 E 12TH
Name: Idx, dtype: object
这篇关于 pandas -从序列的字符串开头删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!