创建包含超链接文本的URL的列

发布于 2025-02-07 16:43:53 字数 362 浏览 1 评论 0原文

我有一个数据源,其中包含超链接的文本列。当我在大熊猫上阅读时,超链接消失了。我仍然想获取每个行的URL,并将其创建为一个称为“ URL”的新列。

因此,想法是创建一个包含URL的新列。在此示例中,PANDAS DataFrame将有4列:

  1. 协议代码
  2. URL
  3. 实体名称
  4. 协议日期

I have a data source that has a column containing text that is hyperlinked. When I read at pandas, the hyperlinks are gone. I want to still get the URL of each of the rows and create it into a new column called "URL".

enter image description here

So, the idea is to create a new column that contains the URL. In this example, the pandas dataframe will have 4 columns:

  1. Agreement Code
  2. URL
  3. Entity Name
  4. Agreement Date

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

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

发布评论

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

评论(1

梨涡少年 2025-02-14 16:43:53

据我所知在这里。此外,您可以使用OpenPyXl来完成此任务:

import openpyxl

### Loads the worksheet
wb = openpyxl.load_workbook('file_name.xlsx')
ws = wb.get_sheet_by_name('sheet_name')

### You can access the hyperlinks like this by changing row number
print(ws.cell(row=2, column=1).hyperlink.target)

您可以迭代行以获取所有超链接并存储在新列中。有关OpenPyXl的更多详细信息,请参阅 docs

As per my knowledge pandas doesn't have this functionality as there is an open feature request for hyperlinks here. Moreover you can use openpyxl to accomplish this task:

import openpyxl

### Loads the worksheet
wb = openpyxl.load_workbook('file_name.xlsx')
ws = wb.get_sheet_by_name('sheet_name')

### You can access the hyperlinks like this by changing row number
print(ws.cell(row=2, column=1).hyperlink.target)

You can iterate row-wise to get all the hyperlinks and store in a new column. For more details regarding openpyxl please refer the docs.

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