Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中从字符串中删除前导文本字符_Python_Regex_Pandas - Fatal编程技术网

在python中从字符串中删除前导文本字符

在python中从字符串中删除前导文本字符,python,regex,pandas,Python,Regex,Pandas,我想提取第一个数字之后的所有数据,包括数字。请参阅dataframe中的解决方案列。所以像“医院2019巷”这样的东西会变成“2019巷” 我试着沿着下面的线条看一些东西,但我正在挣扎,头撞在墙上。请让我知道我的错误的方式 import pandas as pd import re df = pd.DataFrame({'fix_this_field':['dogstreet 1234, st, texas 57500', 'animal hospital of dallas, 233 medi

我想提取第一个数字之后的所有数据,包括数字。请参阅dataframe中的解决方案列。所以像“医院2019巷”这样的东西会变成“2019巷”

我试着沿着下面的线条看一些东西,但我正在挣扎,头撞在墙上。请让我知道我的错误的方式

import pandas as pd
import re
df = pd.DataFrame({'fix_this_field':['dogstreet 1234, st, texas 57500', 'animal hospital of dallas, 233 medical ln '], 'needed solution':['1234, st texas 57500', '233 medical ln']})
df #look what i want

使用
split

x = 'hospital2019 lane'
r = re.compile("^([a-zA-Z]+)([0-9]+)")
m = r.match(x)
m.groups()
# it stops at 2019.   I want 2019 lane.....('hospital', '2019')

如果必须使用正则表达式,请尝试以下操作:

  • 正则表达式:
    (?:[a-zA-Z])([0-9]+.*)
reg=re.compile('(?:[a-zA-Z,])([0-9]+.*))
def清洁(col):
如果re.findall(reg,col)else无,则返回re.findall(reg,col)[0]
df.fix\u此\u字段。应用(干净)
出[1]:
德克萨斯州圣路易斯大街0 1234号,邮编57500
1233医疗级别
名称:修复此字段,数据类型:对象

我找到了
df.fix_这个字段。apply(lambda x:x[re.search(“\d”,x.start():])
df.fix_这个字段。apply(lambda x:”.join(re.split(“(\d)”,x,1)[1:)
的速度是
df.fix_这个字段的几倍

请显示您从这个正则表达式中得到了什么。@Prune更新的tymay是否可以使用try int()循环每个字符,除了?但是如果你有大数据集,这会很慢
df.fix_this_field.str.split('(\d)',1).str[1:].apply(''.join)
Out[475]: 
0    1234, st, texas 57500
1          233 medical ln 
Name: fix_this_field, dtype: object
df['col']=df.fix_this_field.str.split('(\d)',1).str[1:].apply(''.join)