Converting hdf5 to csv or tsv files

前端 未结 5 1558
情话喂你
情话喂你 2021-01-02 07:20

I am looking for a sample code which can convert .h5 files to csv or tsv. I have to read .h5 and output should be csv or tsv.

Sample code would be much appreciated,p

5条回答
  •  一向
    一向 (楼主)
    2021-01-02 07:50

    Python:

    import numpy as np
    import h5py
    np.savetxt(sys.stdout, h5py.File('foo.h5')['dataname'], '%g', ',')
    

    Some notes:

    1. sys.stdout can be any file, or a file name string like "out.csv".
    2. %g is used to make the formatting human-friendly.
    3. If you want TSV just use '\t' instead of ','.
    4. I've assumed you have a single dataset name within the file (dataname).

提交回复
热议问题