Pandas DataFrame concat vs append

后端 未结 4 1304
盖世英雄少女心
盖世英雄少女心 2020-11-28 03:36

I have a list of 4 pandas dataframes containing a day of tick data that I want to merge into a single data frame. I cannot understand the behavior of concat on my timestamps

4条回答
  •  佛祖请我去吃肉
    2020-11-28 04:11

    I have implemented a tiny benchmark (please find the code on Gist) to evaluate the pandas' concat and append. I updated the code snippet and the results after the comment by ssk08 - thanks alot!

    The benchmark ran on a Mac OS X 10.13 system with Python 3.6.2 and pandas 0.20.3.

    +--------+---------------------------------+---------------------------------+
    |        | ignore_index=False              | ignore_index=True               |
    +--------+---------------------------------+---------------------------------+
    | size   | append | concat | append/concat | append | concat | append/concat |
    +--------+--------+--------+---------------+--------+--------+---------------+
    | small  | 0.4635 | 0.4891 | 94.77 %       | 0.4056 | 0.3314 | 122.39 %      |
    +--------+--------+--------+---------------+--------+--------+---------------+
    | medium | 0.5532 | 0.6617 | 83.60 %       | 0.3605 | 0.3521 | 102.37 %      |
    +--------+--------+--------+---------------+--------+--------+---------------+
    | large  | 0.9558 | 0.9442 | 101.22 %      | 0.6670 | 0.6749 | 98.84 %       |
    +--------+--------+--------+---------------+--------+--------+---------------+
    

    Using ignore_index=False append is slightly faster, with ignore_index=True concat is slightly faster.

    tl;dr No significant difference between concat and append.

提交回复
热议问题