我正在使用Enthought Canopy python安装。

我添加了xlwt,xlrd和openpyxl软件包。

制作一个非常简单的DataFrame并尝试将其写入两种类型的excel格式-fn.xls和fn.xlsx

写入fn.xls(使用xlwt包)的工作原理。

但是尝试编写fn.xlsx(使用openpyxl?或xlrd?)程序包失败,并出现以下投诉:ValueError: No Excel writer 'openpyxl'

data = {'year': [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012],
        'team': ['Bears', 'Bears', 'Bears', 'Packers', 'Packers', 'Lions', 'Lions', 'Lions'],
        'wins': [11, 8, 10, 15, 11, 6, 10, 4],
        'losses': [5, 8, 6, 1, 5, 10, 6, 12]}
football = pd.DataFrame(data, columns=['year', 'team', 'wins', 'losses'])
print football

#works
football.to_excel('football.xls', index=False)
#fails:  ValueError: No Excel writer 'openpyxl'
football.to_excel('football.xlsx', index=False)


pd.show_versions()的输出:

pd.show_versions()的输出:pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Darwin
OS-release: 14.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.14.0
nose: 1.3.0
Cython: None
numpy: 1.8.0
scipy: 0.14.0
statsmodels: None
IPython: 2.3.0
sphinx: None
patsy: None
scikits.timeseries: None
dateutil: 2.2
pytz: 2013.8
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.3.1
openpyxl: 2.0.3
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
bq: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None


我只是在启动时注意到user_warning ...


  /Users/slater/canopy_64/User/lib/python2.7/site-packages/pandas/io/excel.py:626:
  
  UserWarning:目前不支持已安装的openpyxl。
  
  使用> = 1.6.1和  openpyxl_compat.stop_ver))


不确定为什么有想法的机盖会将不兼容版本的软件包放在同一部署程序包中。

最佳答案

https://support.enthought.com/entries/46335594--RESOLVED-Pandas-Installed-openpyxl-is-not-supported-at-this-time-version-warning-


  仅机盖订户:请注意,如果您实际上正在使用openpyxl
  读取熊猫电子表格,然后由于
  熊猫,您必须降级openpyxl

关于python - 使用pandas.to_excel()时没有Excel编写器'openpyxl',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27569126/

10-12 22:07