Converting hdf5 to csv or tsv files

前端 未结 5 1555
情话喂你
情话喂你 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:31

    import numpy as np
    import h5py
    
    with h5py.File('chunk0003.hdf5','r') as hf:
        print('List of arrays in this file: \n', hf.keys())
    ### This lists arrays in the file [u'_self_key', u'chrms1', u'chrms2', u'cuts1', u'cuts2', u'misc', u'strands1', u'strands2']
    
    r1 = h5py.File('chunk0003.hdf5','r')
    a = r1['chrms1'][:]
    b = r1['chrms2'][:]
    c = r1['cuts1'][:]
    d = r1['cuts2'][:]
    e = r1['strands1'][:]
    f = r1['strands2'][:]
    r1.close()
    table=np.array([a,b,c,d,e,f])
    table2=table.transpose()
    np.savetxt('chunk0003.txt',table2,delimiter='\t')
    

提交回复
热议问题