Pandas - pandas.DataFrame.from_csv vs pandas.read_csv

后端 未结 2 1211
礼貌的吻别
礼貌的吻别 2021-01-01 10:20

What\'s the difference between:

pandas.DataFrame.from_csv, doc link: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_csv.htm

相关标签:
2条回答
  • 2021-01-01 11:02

    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_col is 0 or None, parse_dates is True or False for read_csv and DataFrame.from_csv respectively) and read_csv supports more arguments (in from_csv they are just not passed through).

    Apart from that, it is recommended to use pd.read_csv.
    DataFrame.from_csv exists 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.

    0 讨论(0)
  • 2021-01-01 11:11

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

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

    0 讨论(0)
提交回复
热议问题