Created
March 1, 2018 23:38
-
-
Save martjanz/853a3825f602ee8b6746740f2abd4741 to your computer and use it in GitHub Desktop.
Export HDF5 tables to CSV files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Export HDF5 tables to csv files | |
| """ | |
| import argparse | |
| import os | |
| import pandas as pd | |
| parser = argparse.ArgumentParser(description='Export HDF5 tables to csv files.') | |
| parser.add_argument('-o', '--h5', dest='h5_path', required=True, | |
| help='Path to HDF5 file.') | |
| parser.add_argument('-d', '--csv', dest='csv_path', default='./', | |
| help='Path where csv files will be stored (default: current path)') | |
| # Parse arguments | |
| args = parser.parse_args() | |
| # Check if HDF5 file exists | |
| if not os.path.isfile(args.h5_path): | |
| print 'ERROR: hdf5 file does not exists.' | |
| exit(-1) | |
| # Open HDF5 file | |
| store = pd.HDFStore(args.h5_path) | |
| tables = store.keys() | |
| # Check if destination path exists | |
| if not os.path.isdir(args.csv_path): | |
| print 'ERROR: destination path does not exists.' | |
| exit(-1) | |
| # Store tables as csv filesa | |
| for table in tables: | |
| table_name = table.replace('/', '') | |
| store[table].to_csv(os.path.join(args.csv_path, table_name + '.csv')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pandas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment