我进行了一项测试,测试了 10 种写入 DataFrame 的方法和 10 种读取 DataFrame 的方法。我在这里找到了测试(我做了一些调整并将 Parquet 添加到列表中)最好的方法是:
df.to_feather('test.feather') :
39.34544535900204s
table=pyarrow.Table.from_pandas(df)
pq.write_table(table, "test_parquet_write_snappy_dict.parquet",
use_dictionary=True, version='2.0', compression='snappy') :
40.6873751259991s
table=pyarrow.Table.from_pandas(df, nthreads=4)
pq.write_table(table, "test_parquet_write_snappy_dict.parquet",
use_dictionary=True, version='2.0', compression='snappy') :
41.051620177000586s
Run Code Online (Sandbox Code Playgroud)
为了写作
和
pd.read_hdf('test_fixed.hdf', 'test') :
1.5275615360005759
pd.read_feather('test.feather') :
20.635139821002667
pd.read_pickle('test.pkl') :
37.21131302599679
Run Code Online (Sandbox Code Playgroud)
为了阅读。
这是数据框:
sz = 50000000
df = pd.DataFrame({'A': randn(sz), 'B': randn(sz), 'C': randn(sz), 'D': randn(sz)})
Run Code Online (Sandbox Code Playgroud)
我有两个问题。为什么read_hdf比 read_feather 快 20 倍,而to_hdf在前三个写入测试中却没有?
第二个,40 秒对于我的需求来说仍然太慢。有没有办法提高这个速度?通过使用不同的参数to_feather或write_table使用我不知道的函数/模块?
我不要求别人来找我,我自己可以做这件事,我不想浪费任何人的时间。我正在寻找一个已经知道这个问题并且可以引导我找到他所知道的最快方法的人。