Python 如何使用pandas在一个单元格中输出具有多个URL的excel文件?
我的一个dataframe元素包含html格式的文本:这是,这是 我想将此数据框保存在excel文件中 excel文件能否显示字符串,因为这是google,这是yahoo,在一个单元格中有两个URLPython 如何使用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&
谢谢您可以这样做:
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。