使用pandas保存h5文件

pandas读取的数据保存成h5文件,再次读取速度会快一些。

import pandas as pd
import os
fname = 'df.h5'
if not os.path.exists(fname):
    h5 = pd.HDFStore(fname,'w', complevel=4, complib='blosc')
    df = get_df()
    h5['df'] = df
    h5.close()
else:
    h5 = pd.HDFStore(fname,'r')
    df = h5['df']
    h5.close()

标签: pandas, h5

添加新评论