我在文件中有数据,我需要将其写入特定列中的CSV文件.文件中的数据如下:
002100
002077
002147
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的:
import csv
f = open ("file.txt","r")
with open("watout.csv", "w") as output:
for line in f :
c.writerows(line)
Run Code Online (Sandbox Code Playgroud)
它始终写在第一列.我怎么能解决这个问题?谢谢.
Lai*_*ith 10
这就是我解决问题的方法
f1 = open ("inFile","r") # open input file for reading
with open('out.csv', 'wb') as f: # output csv file
writer = csv.writer(f)
with open('in.csv','r') as csvfile: # input csv file
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
row[7] = f1.readline() # edit the 8th column
writer.writerow(row)
f1.close()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30650 次 |
| 最近记录: |