Python Pandas 中的引擎 read_csv [英] Engines in Python Pandas read_csv

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

问题描述

在 python 中的 Pandas 中的 pd.read_csv() 方法的文档中,在描述sep"参数时,提到了 C 引擎和 Python 引擎等引擎.

In the document for pd.read_csv() method in pandas in python while describing the "sep" parameter there is a mention of engines such as C engine and Python engine.

文档链接是:https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

这些引擎是什么?每个引擎的作用是什么?是否有任何类比可以帮助更好地理解这些引擎?

What are these engines? What is the role of each engine? Is there any analogy which can help understand these engines better?

推荐答案

pd.read_csv 文档说明了c"(默认)和python"引擎之间的具体区别.名称指示编写解析器的语言.具体来说,文档说明:

The pd.read_csv documentation notes specific differences between 'c' (default) and 'python' engines. The names indicate the language in which the parsers are written. Specifically, the docs note:

pandas 尽可能使用 C 解析器(指定为 engine='c'),但如果指定了 C 不支持的选项,则可能会回退到 Python.

Where possible pandas uses the C parser (specified as engine='c'), but may fall back to Python if C-unsupported options are specified.

以下是您应该注意的主要区别(从 v0.23.4 开始):

Here are the main differences you should note (as of v0.23.4):

  • c"更快,而python"目前功能更完整.
  • 'python' 支持 skipfooter,而 'c' 不支持.
  • 'python' 支持灵活的 sep 除了单个字符(inc regex),而 'c' 不支持.
  • 'python' 支持 sep=Nonedelim_whitespace=False,这意味着它可以自动检测分隔符,而 'c'没有.
  • 'c' 支持 float_precision,而 'python' 不支持(或不需要).
  • 'c' is faster, while 'python' is currently more feature-complete.
  • 'python' supports skipfooter, while 'c' does not.
  • 'python' supports flexible sep other than a single character (inc regex), while 'c' does not.
  • 'python' supports sep=None with delim_whitespace=False, which means it can auto-detect a delimiter, while 'c' does not.
  • 'c' supports float_precision, while 'python' does not (or not necessary).

版本说明:

  • dtype 'python' v0.20.0+ 支持.
  • delim_whitespace 'python' v0.18.1+ 支持.

请注意,随着功能的开发,上述内容可能会发生变化.您应该检查 IO 工具(文本、CSV、HDF5, ...) 如果您在更高版本中看到意外行为.

Note the above may change as features are developed. You should check IO Tools (Text, CSV, HDF5, …) if you see unexpected behaviour in later versions.

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

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