更新时间:2022-03-03 09:28:21
感谢@qwwqwwq,我发现pandas内置了用于数据帧的to_pickle
方法.我做了一个快速的时间测试:
Thanks to @qwwqwwq I discovered that pandas has a built-in to_pickle
method for dataframes. I did a quick time test:
In [1]: %timeit pickle.dump(df, open('test_pickle.p', 'wb'))
10 loops, best of 3: 91.8 ms per loop
In [2]: %timeit df.to_pickle('testpickle.p')
10 loops, best of 3: 88 ms per loop
因此,似乎内置函数仅略胜一筹(对我而言,这很有用,因为这意味着使用内置函数可能不值得重构代码)-希望这对某人有帮助!
So it seems that the built-in is only narrowly better (to me, this is useful because it means it's probably not worth refactoring code to use the built-in) - hope this helps someone!