Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用pandas在一个单元格中输出具有多个URL的excel文件?_Python_Pandas - Fatal编程技术网

Python 如何使用pandas在一个单元格中输出具有多个URL的excel文件?

Python 如何使用pandas在一个单元格中输出具有多个URL的excel文件?,python,pandas,Python,Pandas,我的一个dataframe元素包含html格式的文本:这是,这是 我想将此数据框保存在excel文件中 excel文件能否显示字符串,因为这是google,这是yahoo,在一个单元格中有两个URL 谢谢您可以这样做: import re import pandas as pd df = pd.DataFrame({"text": ['This is <a href="https://www.google.com">google</a&

我的一个dataframe元素包含html格式的文本:这是,这是

我想将此数据框保存在excel文件中

excel文件能否显示字符串,因为这是google,这是yahoo,在一个单元格中有两个URL


谢谢

您可以这样做:

import re
import pandas as pd

df = pd.DataFrame({"text": ['This is <a href="https://www.google.com">google</a> and this is <a href="https://www.yahoo.com">yahoo</a>']})

df["links"] = df.text.apply(lambda x: re.findall(r'<a href="(.+?)".+?', x))
df.text = df.text.str.replace(r"<a.+?>(.+?)</a>", r'\1', regex=True)
print(df)
#                               text                                            links
#0  This is google and this is yahoo  [https://www.google.com, https://www.yahoo.com]

然后是df.to_excel很可能感谢你,安瓦维奇。但是,我想产生这样的效果:当我通过df.to_excel导出df时,excel中的单元格将在一个单元格中包含2个可单击的URL。