熊猫 - pandas.DataFrame.from_csv 与 pandas.read_csv

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26495408/
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-13 22:35:59  来源:igfitidea点击:

Pandas - pandas.DataFrame.from_csv vs pandas.read_csv

pythoncsvpandas

回答by joris

There is no real difference (both are based on the same underlying function), but as noted in the comments, they have some different default values(index_colis 0 or None, parse_datesis True or False for read_csvand DataFrame.from_csvrespectively) and read_csvsupports more arguments(in from_csvthey are just not passed through).

有没有真正的区别(两者都基于相同的底层函数),但在评论中指出,他们有一些不同的默认值index_col0或无,parse_dates是真的还是假的read_csv,并DataFrame.from_csv分别),并read_csv支持更多的参数(在from_csv他们只是没有通过)。

Apart from that, it is recommended to use pd.read_csv.
DataFrame.from_csvexists merely for historical reasons and to keep backwards compatibility (plans are to deprecate it, see here), but all new features are only added to read_csv(as you can see in the much longer list of keyword arguments). Actually, this should be made more clear in the docs.

除此之外,建议使用pd.read_csv.
DataFrame.from_csv仅出于历史原因而存在并保持向后兼容性(计划弃用它,请参阅此处),但所有新功能仅添加到read_csv(如您在更长的关键字参数列表中所见)。实际上,这应该在文档中更清楚。

回答by ChaimG

Another difference is that pandas.read_csvis 46x to 490x as fast as pandas.DataFrame.from_csv(in my testing).

另一个区别是它的pandas.read_csv速度是pandas.DataFrame.from_csv(在我的测试中)的46 倍到 490 倍。

I tested it on Python 3.4.4 and pandas 0.19.2 on Windows on my proprietary csv file.

我在 Windows 上的 Python 3.4.4 和 pandas 0.19.2 上对我的专有 csv 文件进行了测试。