如何在python中从url中删除额外的文本

2024-10-03 09:21:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在数据框中有超过1000行类似这样的url

我的数据帧中有df['profile']列

http://pbs.twimg.com/profile_images/797804071063343105/KPytXWtY_normal.jpg
http://pbs.twimg.com/profile_images/903374198009188353/pDuYl5Uk_normal.jpg
http://pbs.twimg.com/profile_images/1101088756432396290/5bzisDRx_normal.png 

我只需要从python中的图片url中删除\u normal

我试过这个,但不起作用

df.profile.str.replace(r'_normal', r'')

当我应用这条线时,我得到了行中的轮廓图像。而不是用上一个值替换新值


Tags: 数据comhttpurldfpng图片profile