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)
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)
you can just use:
with pd.ExcelWriter(file_name, options={'strings_to_urls': False}) as writer:
df.to_excel(writer, 'Influence on Policy', columns=colsPol)
Then you don't have to worry about closing your writer file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With