Issue
I am using the following code to copy a dataframe into an Excel document:
dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol)
The problem is that I am getting the following error as the URLs are too long:
Ignoring URL .... 255 characters since it exceeds Excel's limit for URLS
So, I found a solution which is to use:
dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol, options={'strings_to_urls': False})
But I am getting an error of:
TypeError: to_excel() got an unexpected keyword argument 'options'
As obviously options does not work with to_excel
, which is what I am using for a lot of other code in my script (i.e. I want to stick with 'to_excel')
Are there any solutions to my problem?
This is not a duplicate of: How to save in *.xlsx long URL in cell using Pandas as that is not about to_excel (it is about excelwriter)
Solution
Pass the argument options={'strings_to_urls': False}
to the pd.ExcelWriter
call when creating your writer
.
It will look something like this:
writer = pd.ExcelWriter('C:/Users/{}/Desktop/RF Data.xlsx'.format(staName2),options={'strings_to_urls': False})
dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol)
Answered By - Mykola Shchetinin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.