HDF5.to_csv
to_csv(h5file, outdir, sep=" ")
Converts the datasets in an HDF5 file into CSV files inside outdir. The file is loaded into an HDF5Dict and its tree is walked group by group; how a dataset is written depends on its _kind:
lineardatasets — alllineardatasets found at the same group level are treated as columns and concatenated side by side into a single CSV named after that group (<group>.csv; the root level falls back toout.csv). Each column header is the dataset's_nameattribute, or its key if_nameis absent.compounddatasets — each one is written to its own CSV file, since a structured array already holds multiple named columns. The file is named after the dataset's_nameattribute, or its key (<name>.csv).
Sub-groups are traversed recursively, so a nested HDF5 hierarchy produces one CSV per group of linear columns plus one CSV per compound dataset. _attrs metadata is not exported.
Parameters
- h5file : str or Path
- Source HDF5 file.
- outdir : str or Path
- Destination directory, created if it does not exist.
- sep : str, optional
- Column separator. Default
" ".
Example
Given an HDF5 file rates.hdf5 with this structure:
/
└── rates/ (group)
├── T linear _name="T"
├── k1 linear _name="k1"
├── k2 linear _name="k2"
└── output_units compound _name="output_units" (col1, col2, col3)
produces two files in out/:
rates.csv— the threelineardatasets merged as columns:
output_units.csv— thecompounddataset, one column per field: