您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在python中将大型csv文件写入hdf5?

如何在python中将大型csv文件写入hdf5?

您可以使用chunksize参数以块的形式读取CSV文件,并将每个块附加到HDF文件中:

hdf_key = 'hdf_key'
df_cols_to_index = [...] # list of columns (labels) that should be indexed
store = pd.hdfstore(hdf_filename)

for chunk in pd.read_csv(csv_filename, chunksize=500000):
    # don't index data columns in each iteration - we'll do it later ...
    store.append(hdf_key, chunk, data_columns=df_cols_to_index, index=False)
    # index data columns in hdfstore

store.create_table_index(hdf_key, columns=df_cols_to_index, optlevel=9, kind='full')
store.close()
python 2022/1/1 18:29:59 有537人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶