擅长:python、mysql、java
<p>您的问题:中没有“\n”作家.作家这就是为什么你总是发现错误。对于csv,你必须一次写一行。下面的代码就是您想要的。在</p>
<pre><code>import csv
FieldIP = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
FieldOP = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
signalIP = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.10,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.20]
signalOP = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.10,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.20]
NameIP = "JDP123"
TypeIP = "ID123"
NameOP = "JDP124"
TypeOP = "ID124"
newDirRH = "C:/VSMPlots"
newfile = newDirRH + "/TabulatedStatsVSM1.csv"
with open(newfile, "wb") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["NameIP", "TypeIP", "NameOP", "TypeOP"])
writer.writerow([NameIP, TypeIP, NameOP, TypeOP])
writer.writerow([" "])
writer.writerow(["FieldIP", "SignalIP", "FieldOP", "SignalOP"])
for field, signal, field1, signal1 in zip(FieldIP, signalIP, FieldOP, signalOP):
writer.writerow([field, signal, field1,signal1])
print "Done"
</code></pre>