Answer a question

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")

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)

I got warning.

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))

And in output.xlsx cells with long URL were empty, and URLs become hyperlinks.

How to fix this?

Answers

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()
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐