Converting hdf5 to csv or tsv files

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,please help as i have stuck on it for last few days.I followed wrapper classes but don't know how to use that.I am not a good programmer so facing lot of problem.

please help thanks a lot in advance


You can also use h5dump -o dset.asci -y -w 400 dset.h5

  • -o dset.asci specifies the output file
  • -y -w 400 specifies the dimension size multiplied by the number of positions and spaces needed to print each value. You should take a very large number here.
  • dset.h5 is of course the hdf5 file you want to convert
  • This converts it to an ascii file, which is easy imported to excel, from where you can easily save it as a .csv (save as within excel, and specify file format). I did it a couple of times, and it worked for me. source


    Example of HDF5 to CSV conversion can be found at https://github.com/amgreenstreet/Million-Song-Dataset-HDF5-to-CSV

    It uses Python and converts Million Songs Dataset from HDF5 to CSV format.

    I strongly recommend to use Python(x,y) version http://python-xy.github.io/ because this example uses additional Python packages like NumPy and PyTables. Python(x,y) has these packages included.


    Python:

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

    Some notes:

  • sys.stdout can be any file, or a file name string like "out.csv" .
  • %g is used to make the formatting human-friendly.
  • If you want TSV just use 't' instead of ',' .
  • I've assumed you have a single dataset name within the file ( dataname ).
  • 链接地址: http://www.djcxy.com/p/79114.html

    上一篇: 系列化

    下一篇: 将hdf5转换为csv或tsv文件