Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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
Regex 使正则表达式在获取consequentive数字时更加具体_Regex_Python 3.x_String_Pandas_Text - Fatal编程技术网

Regex 使正则表达式在获取consequentive数字时更加具体

Regex 使正则表达式在获取consequentive数字时更加具体,regex,python-3.x,string,pandas,text,Regex,Python 3.x,String,Pandas,Text,如上图所示,我有以下df。我使用以下公式仅获取consequentive数字 import pandas as pd df= pd.DataFrame({'Data':['123456A122 119999 This 1234522261 1A1619 BL171111 A-1-24', '134456 dont 12-23-34-45-5-6 Z112 NOT 01-22-2001',

如上图所示,我有以下
df
。我使用以下公式仅获取consequentive数字

import pandas as pd
df= pd.DataFrame({'Data':['123456A122 119999 This 1234522261 1A1619 BL171111 A-1-24',
                                  '134456 dont 12-23-34-45-5-6 Z112 NOT 01-22-2001',
                                  'mix: 1A25629Q88 or A13B ok'], 
                          'IDs': ['A11','B22','C33'],
                          }) 
这收集了很多我不想要的东西,比如
BL171111
中的
171111
123456
中的
123456A122
等等

我想下面的输出,只拿起6个连续数字

reg = r'((?:[\d]-?){6,})'
df['new'] = df['Data'].str.findall(reg) 

    Data    IDs new
0               [123456,119999, 1234522261, 171111]
1               [134456, 12-23-34-45-5-6, 01-22-2001]
2               []
如何将正则表达式更改为so

    Data    IDs new
0               [119999]
1               [134456]
2               []

将正则表达式更改为使用单词边界(
\b
),并将位数精确限制为6,如下所示:

reg = r'((?:[\d]-?){6,})'
这将查找单词边界、6个数字和另一个单词边界

这是一个.df.Data.str.split(expand=True).apply(pd.to_numeric,errors='concurve').bfill(1).iloc[:,0]?
reg = r'(\b\d{6}\b)'