【发布时间】:2019-07-15 11:42:10
【问题描述】:
我正在尝试找到一个正则表达式模式并将其放入数据框列中,同时遍历另一列的值。
问题:直到第 60 次迭代之前它都可以创造奇迹,但它只显示 NaN。我有 400 000 个条目,其中大部分应该匹配。
为什么会这样,我该如何解决?
import re
new_mail = []
for urlcore in re.finditer('https*://[www.]*(\S*).*\.(fr|com)',str(df['Site_Web'])):
yolo = urlcore.group(1)
new_mail.append(yolo)
df['urlcore'] = pd.Series(new_mail)
df['urlcore'] = df['urlcore'].str.replace('.', '', regex=True).replace('-', '', regex=True)
【问题讨论】:
-
您是否使用应该匹配但不匹配的正则表达式字符串测试了上面的字符串?可能是你需要修改正则表达式。
-
你的正则表达式看起来很奇怪,[www.] mach with
waaaaabbbabb,-----.`` and the part in the core (\S*). match wit someting lik thisgoogle-------------------。 com` -
Edit你的问题并在
df['Site_Web']中显示三行 -
尝试使用
https*:\/\/(www\.)?.*\.(fr|com) -
ThomasAyoub 你需要在
https?中使用?,因为*与httpssss 匹配