def SaveToPklFile(Data,OutputDir):
df_train,df_test = Data
if(os.path.exists(OutputDir) == False):
os.makedirs(OutputDir)
with open('%s/train.pkl' % OutputDir, 'wb') as o_file:
pickle.dump(df_train, o_file, -1)
o_file.close()
max_bytes = 2 ** 31 - 1
bytes_out = pickle.dumps(df_test)
n_bytes = len(bytes_out)
with open('%s/test.pkl' % OutputDir, 'wb') as o_file:
for idx in range(0, n_bytes, max_bytes):
o_file.write(bytes_out[idx:idx + max_bytes])
# too big for pickle
#pickle.dump(df_test, o_file, -1)
o_file.close()
# with open('%s/test.csv' % OutputDir, 'w') as o_file:
# o_file.write('%s\n' % (','.join(list(df_test.columns))))
# for idx in df_test.index:
# rec = [str(v) for v in df_test.ix[idx].values]
# o_file.write('%s\n' % (','.join(rec)))
# o_file.close()
评论列表
文章目录