来自 Killian Mie,bcolz mailing list:
通过pandas.read_csv() 分块读取 csv,将字符串列从 Python 对象 dtype 转换为固定长度的 numpy dtype,例如“S20”,然后作为 numpy 数组附加到 ctable。
另外,在创建 ctable 时设置 chunklen=1000000(或类似),这将避免在 /data 文件夹下创建数百个文件(虽然可能不是压缩的最佳选择)
上述两个步骤对我来说效果很好(2000 万行,40-60 列)。
试试这个:
df0 = ddf.from_castra("data.castra")
df = odo.odo(df0, pd.DataFrame)
names = df.columns.tolist()
types = ['float32', 'float32', 'S20'] # adjust 'S20' to your max string length needs
cols = [bcolz.carray(df[c].values, dtype=dt) for c, dt in zip(names, types)]
ct = bcolz.zeros(0, dtype=np.dtype(zip(names, types)),
mode='w', chunklen=1000000,
rootdir="data.bcolz")
ct.append(cols)