[英]How to solve the delimiter error while using to_csv function in pandas
This is a followup question on how to write a single row cell by cell and fill it in csv file 这是有关如何按单元写入单个行单元并将其填充到csv文件中的后续问题
import pandas as pd
delim = "@@@"
# just for abrevation
tmp = pd.read_csv("mycsv.csv",sep='@@@')
tmp.loc[0,:] = "None"
tmp.to_csv("mycsv.csv",sep=delim,index=False)
I am getting follow error . 我正在跟踪错误。 Please suggest some correct solution
请提出一些正确的解决方案
self.writer = csv.writer(f, **writer_kwargs)
TypeError: "delimiter" must be a 1-character string
Exception ignored in: <module 'threading' from
Traceback (most recent call last):
line 1296, in _shutdown
_main_thread._delete()
File /share/python-3.6.1/linux_x86_64/lib/python3.6/threading.py", line 1015,
in _delete
del _active[get_ident()]
KeyError: 140613724829696
As per the Error
and the to_csv documentation, it supports only one character. 根据
Error
和to_csv文档,它仅支持一个字符。
Whereas read_csv supports str
. 而read_csv支持
str
。 That's why it works why reading and failing at writing. 这就是为什么阅读和写作失败的原因。 You might need to change the delimiter to one character.
您可能需要将分隔符更改为一个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.