pandas 中可用于to_excel功能的引擎 [英] Engines available for to_excel function in pandas

查看:268
本文介绍了 pandas 中可用于to_excel功能的引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当使用to_excel函数将数据帧保存到大熊猫中的excel文件(.xlsx)时,我们都会提供一个选项,以指定要用来完成该过程的引擎.我的问题是,所有可用的引擎是什么?例如一个引擎是"xlsxwriter";同样,还有哪些其他可用选项?

Whenever we save a dataframe to an excel file (.xlsx) in pandas using to_excel function, we are given an option to specify the engine using which we want can complete the process. My question is what all are the engines available for this?. For e.g. one engine is "xlsxwriter"; similarly what are the other options available?

推荐答案

Pandas定义了Excel的默认编写器,请参见

Pandas defines default writers for Excel, see pandas/io/excel/_util.py:

def _get_default_writer(ext):
    """
    Return the default writer for the given extension.
    Parameters
    ----------
    ext : str
        The excel file extension for which to get the default engine.
    Returns
    -------
    str
        The default engine for the extension.
    """
    _default_writers = {
        "xlsx": "openpyxl",
        "xlsm": "openpyxl",
        "xls": "xlwt",
        "ods": "odf",
    }
    xlsxwriter = import_optional_dependency(
        "xlsxwriter", raise_on_missing=False, on_version="warn"
    )
    if xlsxwriter:
        _default_writers["xlsx"] = "xlsxwriter"
    return _default_writers[ext]

因此,如果安装了模块,则扩展名xlsx的默认值为xlsxwriter,否则为openpyxl.

So the default for extension xlsx will be xlsxwriter, if you have the module installed, otherwise openpyxl.

这篇关于 pandas 中可用于to_excel功能的引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆