pandas.read_csv() 方法中的 `sep` 和 `delimiter` 属性有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49532873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:22:43  来源:igfitidea点击:

What is the difference between `sep` and `delimiter` attributes in pandas.read_csv() method?

pythonpandasdelimiter

提问by GadaaDhaariGeek

What is the difference between sepand delimiterattributes in pandas.read_csv()method?

sep和方法中的delimiter属性有什么区别pandas.read_csv()

Also what is the situation when I would choose one over the other?

另外,当我选择一个而不是另一个时的情况是什么?

In documentation I read something about Python builtin sniffer tool, also in delimiter, it says alternative argument name for sep, then why cant we have only one attribute?

在文档中,我阅读了一些关于 Python 内置嗅探器工具的内容,也在分隔符中,它说sep 的替代参数名称,那么为什么我们不能只有一个属性?

回答by thesilkworm

Confirmation that they are the same thing can be found in the source code:

可以在源代码中确认它们是同一件事:

# Alias sep -> delimiter.
if delimiter is None:
    delimiter = sep

I agree with the other answer that it is best to stick to sep. It seems to be more commonly used, and it is more consistent with other functions such as to_csv, which does not accept delimiter, only sep.

我同意最好坚持的另一个答案sep。好像比较常用,也比较符合其他函数比如to_csv,不接受delimiter,只接受sep

回答by FHTMitchell

They're the same thing. See here.

它们是同一回事。见这里

I assume one is for backwards compatibility. I'd just use sep, it's what I see the most.

我认为一个是为了向后兼容。我只是使用sep,这是我看到最多的。