Created
February 23, 2016 06:27
-
-
Save RobbieClarken/9ea7ceaaa3765f536d95 to your computer and use it in GitHub Desktop.
This file contains 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
with h5py.File('data.hdf5', 'w') as file: | |
dataset = file.create_dataset('dataset', data=df.values) | |
dataset.attrs['index'] = np.array(df.index.tolist(), dtype='S') | |
dataset.attrs['columns'] = np.array(df.columns.tolist(), dtype='S') | |
def make_index(raw): | |
index = raw.astype('U') | |
if index.ndim > 1: | |
return pd.MultiIndex.from_tuples(index.tolist()) | |
else: | |
return pd.Index(index) | |
with h5py.File('data.hdf5') as file: | |
dataset = file['dataset'] | |
index = make_index(dataset.attrs['index']) | |
columns = make_index(dataset.attrs['columns']) | |
df = pd.DataFrame(data=dataset[...], index=index, columns=columns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment