【发布时间】:2018-09-25 09:10:49
【问题描述】:
我有一个只有列标题的 CSV 文件:
cat mycsv.csv
col_1@@@col_2@@@col_3@@@col_3
我必须在 CSV 文件的每个单元格中用 None 值填充一行。有人可以建议我在 Python 和 Pandas 中做到这一点的最佳优化方式吗?
填完行后,csv 文件应如下所示:
cat mycsv.csv
col_1 , col_2 , col_3 , col_3
0@@@None@@@None@@@None
如何插入索引和分隔符是 @@@ 而不是 , ?我收到一个错误:
tmp.to_csv(csvFile,sep='@@@',index=True)
, line 1381, in to_csv
formatter.save()
3.6.1/linux_x86_64/lib/python3.6/site-packages/pandas/formats/format.py", line 1473, in save
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):
File python-3.6.1/linux_x86_64/lib/python3.6/threading.py", line 1015, in
_delete
del _active[get_ident()]
KeyError: 140459817715712
【问题讨论】:
-
您不是在寻找最优化的方法,而是在实施任何方法方面取得了进展?请展示您迄今为止从研究中得到的结果。