如何使用 pandas 在单元格中保存* .xlsx长URL [英] How to save in *.xlsx long URL in cell using Pandas
问题描述
例如,我将Excel文件读入具有2列(ID和URL)的DataFrame中.输入文件中的URL类似于文本(没有超链接):
For example I read excel file into DataFrame with 2 columns(id and URL). URLs in input file are like text(without hyperlinks):
input_f = pd.read_excel("input.xlsx")
观看此DataFrame中的内容-成功读取所有内容,在input_f
中所有URL都可以.之后,当我不想将此文件保存到_excel
Watch what inside this DataFrame - everything was successfully read, all URLs are ok in input_f
. After that when I wan't to save this file to_excel
input_f.to_excel("output.xlsx", index=False)
我得到警告.
路径 \ worksheet.py:836:用户警告:使用以下命令忽略URL "http://这里是长URL" 链接或位置/锚点> 255个字符,因为它超出了Excel的 URLS的限制force_unicode(url))
Path\worksheet.py:836: UserWarning: Ignoring URL 'http:// here long URL' with link or location/anchor > 255 characters since it exceeds Excel's limit for URLS force_unicode(url))
在output.xlsx中,URL长的单元格为空,URL成为超链接.
And in output.xlsx cells with long URL were empty, and URLs become hyperlinks.
该如何解决?
推荐答案
您可以创建一个ExcelWriter对象,该对象具有不将字符串转换为url的选项:
You can create an ExcelWriter object with the option not to convert strings to urls:
writer = pandas.ExcelWriter(r'file.xlsx', engine='xlsxwriter',options={'strings_to_urls': False})
df.to_excel(writer)
writer.close()
这篇关于如何使用 pandas 在单元格中保存* .xlsx长URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!