我有一个如下所示的 CSV 文件:
COL_A,COL_B
12345,A=1$B=2$C=3$
如何读取该文件并将其写回一个新文件,但只是第二行(行)?我希望输出文件包含:
12345,A=1$B=2$C=3$
谢谢!
以下内容读取您的 csv,提取第二行,然后将第二行写入另一个文件。
with open('file.csv') as file:
second_line = list(file)[1]
with open('out.csv', mode = 'w') as file:
file.write(second_line)
outfile = open(outfilename,"w")
with open(filename) as f:
for line in f:
print >> outfile , line.split()[-1]
outfile.close()
只要这些线条实际上看起来像您在 OP 中发布的线条