Python Pandas-在写入to_csv时使用多字符定界符 [英] Python Pandas - use Multiple Character Delimiter when writing to_csv
本文介绍了Python Pandas-在写入to_csv时使用多字符定界符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎pandas to_csv函数仅允许使用单个字符定界符/分隔符.
It appears that the pandas to_csv function only allows single character delimiters/separators.
是否有某种方式允许使用字符串,例如"::"或"%%"?
Is there some way to allow for a string of characters to be used like, "::" or "%%" instead?
我尝试过:
df.to_csv(local_file, sep = '::', header=None, index=False)
并获得:
TypeError: "delimiter" must be a 1-character string
推荐答案
例如:
np.savetxt(file.csv, np.char.decode(chunk_data.values.astype(np.bytes_), 'UTF-8'), delimiter='~|', fmt='%s',encoding=None)
np.savetxt(file.dat, chunk_data.values, delimiter='~|', fmt='%s',encoding='utf-8')
这篇关于Python Pandas-在写入to_csv时使用多字符定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文