t:([] AA:1 2;BB:3 4;CC:5 6)
.hdf5.createFile["diy.h5"]
.hdf5.createGroup["diy.h5";"project"]
.hdf5.createGroup["diy.h5";"project/table"]
{.hdf5.writeData["diy.h5";"project/table/",string x;t x]} each cols t
.hdf5.writeAttr["diy.h5";"project/table";"datatype_kdb";"table"]
.hdf5.writeAttr["diy.h5";"project/table";"kdb_columns";cols t]
Finally this would be the python equivalent:
import h5py as h5
import pandas as pd
import numpy as np
df = pd.DataFrame({"AA":[1, 2], "BB":[3, 4], "CC":[5, 6]})
f = h5.File('forKX.h5','w')
project = f.create_group("project")
table = project.create_group("table")
table.attrs["datatype_kdb"] = np.array( [ord(c) for c in 'table'], dtype=np.int8)
table.attrs["kdb_columns"] = [x.encode('ascii') for x in df.columns] for col in df.columns: table[col] = df[col].to_numpy()
f.close()
All three read in the same way:
q).hdf5.readData[“byKX.h5”;“project/table”] AA BB CC -------- 1 3 5 2 4 6 q).hdf5.readData[“diy.h5”;“project/table”] AA BB CC -------- 1 3 5 2 4 6 q).hdf5.readData[“forKX.h5”;“project/table”] AA BB CC -------- 1 3 5 2 4 6
In the real world tabular data you have from another source in a .h5 will not read straight in to a kdb+ table. You will need to extract the data column by column as I showed in a previous example
If you have a file the interface is unable to read you can still use embedPy to manipulate the data and transfer to kdb+