【发布时间】:2020-12-10 17:26:34
【问题描述】:
我有一个数据框,其中包含一个列名称作为回复,其中包含以下内容
ljaganathan:https://engineering.paypalcorp.com/confluence/pages/viewpage.action?spaceKey=CAL&title=Report+REST+Interface vanbalagan:请参考:https://engineering.paypalcorp.com/confluence/display/GPS/User+Guide+for+Self-serve+Alerts
我只想从只有 URL 的特定列中提取 URL 尝试使用以下代码
import re
re.findall(r'(https?://\S+)', df['replies'])
收到此错误 TypeError:预期的字符串或类似字节的对象
甚至尝试过这个
df["replies"]=df["replies"].astype(str)
pattern = r'(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}[-a-zA-Z0-9()@:%_+.~#?&/=]*)'
df['links'] = ''
df['links']= df["replies"].str.extract(pattern, expand=True)
print(df['links')
获取上述的 NaN 值
有人可以帮我解决上述问题吗?
【问题讨论】: