从基利安三重的bcolz mailing list:通过pandas.read_csv()
在块
读CSV,从Python对象D类的字符串列转换为固定长度numpy的D类,比如“S20”,然后追加为numpy的阵列到ctable 。
此外,设置chunklen=1000000
(或类似)在ctable创作这将避免/ data文件夹下创建数百个文件(可能不是最佳的,虽然压缩)
上述2步的工作很适合我(20元行,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)