pandas read_excel与超链接 [英] Pandas read_excel with Hyperlink

查看:261
本文介绍了 pandas read_excel与超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel电子表格,我正在阅读一个Pandas DataFrame:

  df = pd.read_excel( xls)

但是,电子表格的其中一列包含与其相关联的超链接的文本。如何访问熊猫中的基础超链接?

解决方案

这可以用openpyxl完成,我不知道它是否可能熊猫在所有。以下是我如何做:

  import openpxyl 

wb = openpyxl.load_workbook('yourfile $ x
ws = wb.get_sheet_by_name('Sheet1')
print(ws.cell(row = 2,column = 1).hyperlink.target)

您还可以使用iPython,并设置与超链接对象相等的变量:



t = ws.cell(row = 2,column = 1).hyperlink



然后执行 t。,然后按选项卡查看所有可以使用或从对象访问的选项。


I have an Excel spreadsheet that I am reading into a Pandas DataFrame:

df = pd.read_excel("file.xls")

However, one of the columns of the spreadsheet contains text which have a hyperlink associated with it. How do I access the underlying hyperlink in Pandas?

解决方案

This can be done with openpyxl, I'm not sure its possible with Pandas at all. Here's how I've done it:

import openpxyl

wb = openpyxl.load_workbook('yourfile.xlsm')
ws = wb.get_sheet_by_name('Sheet1')
print(ws.cell(row=2, column=1).hyperlink.target)

You can also use iPython, and set a variable equal to the hyperlink object:

t = ws.cell(row=2, column=1).hyperlink

then do t. and press tab to see all the options for what you can do with or access from the object.

这篇关于 pandas read_excel与超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆