【发布时间】:2019-11-29 12:42:41
【问题描述】:
我有 11k 个 csv 文件,其中只有两行它们看起来像这样
---------------------------
| A0.31 |
---------------------------
some data | |
---------------------------
我只希望它们在一行中
---------------------------
some data | A0.31 |
---------------------------
我有这段代码,但它只是替换了没有将它们放在一行中的值
import csv, os
with open('path/to/filename') as inf, open('path/to/filename_temp', 'w') as outf:
reader = csv.reader(inf)
writer = csv.writer(outf)
for line in reader:
if line[1] == '0':
...
... # as above
os.remove('path/to/filename')
os.rename('path/to/filename_temp', 'path/to/filename')
【问题讨论】: