python - (PYTHON) to_excel - 忽略 URL...255 个字符,因为它超过了 Excel 的 URLS 限制

标签 python pandas

我正在使用以下代码将数据框复制到 Excel 文档中:

dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol)

问题是我收到以下错误,因为 URL 太长了:

Ignoring URL .... 255 characters since it exceeds Excel's limit for URLS

所以,我找到了一个解决方案,可以使用:

dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol, options={'strings_to_urls': False})

但是我得到一个错误:

TypeError: to_excel() got an unexpected keyword argument 'options'

很明显,选项不适用于 to_excel,这是我在脚本中用于许多其他代码的方式(即我想坚持使用“to_excel”)

我的问题有什么解决方案吗?

这不是以下内容的副本:How to save in *.xlsx long URL in cell using Pandas因为那不是关于 to_excel(它是关于 excelwriter)

最佳答案

在创建 writer 时,将参数 options={'strings_to_urls': False} 传递给 pd.ExcelWriter 调用。 它看起来像这样:

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)

关于python - (PYTHON) to_excel - 忽略 URL...255 个字符,因为它超过了 Excel 的 URLS 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46756302/

相关文章:

python - 从字符串中获取关键字列表

python - 使用 numpy 用索引矩阵对向量进行索引,类似于 MATLAB

python - pandas 选择数据透视表的子集

python - Ubuntu 19.11 中 QtCreator v4.11 的 LLDB-9 错误

python - 在所有 pandas 数据框列上应用 statsmodels 自回归函数

python - 如何将 'explode' Pandas 列值转换为唯一行

python - Pandas 系列 : Log Normalize

Python;将数据帧输出写入不同的子目录

python - 将不同的列加入其中之一 - python

pandas - 标准化 Pandas 数据框中的一列