python编码pandas dataframe的URL

发布于 2025-02-09 02:25:34 字数 754 浏览 2 评论 0原文

我想清理page_url pandas dataframe下的字段df例如

df

page_url
https%3A%2f%2f%2fwww.google.com%2F

我们的目标是如下:

page_url
https://www.google.com/

我尝试了: df ['page_url']。str.Strip()。替换(dict(zip([“%2F”,“%3A”),[/“,”,“:”])),REGEX = true)

它适用于此示例,但是dataframe page_url列具有其他值,例如'%2b'或其他字符串,只想看看是否有另一种方法可以在Python 3中执行此操作。需要更换每个字符串,而不是写下每个字符串。谢谢

I want to cleanup the page_url field under pandas dataframe df for example

df:

page_url
https%3A%2F%2Fwww.google.com%2F

Our goal is to clean it up like below:

page_url
https://www.google.com/

I've tried:
df['page_url'].str.strip().replace(dict(zip(["%2F", "%3A"], ["/", ":"])),regex=True)

It works for this example, however the dataframe page_url column has other values like '%2B' or other strings, just want to see if there is an alternative way to do that in Python 3 instead of writing down each string needs to be replace. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎的声音 2025-02-16 02:25:34
import urllib.parse
urllib.parse.unquote("https%3A%2F%2Fwww.google.com%2F")
# 'https://www.google.com/'

所以我们需要的是

df['page_url'].apply(urllib.parse.unquote)
import urllib.parse
urllib.parse.unquote("https%3A%2F%2Fwww.google.com%2F")
# 'https://www.google.com/'

So what we need is

df['page_url'].apply(urllib.parse.unquote)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文