[英]Export a table in CSV file
我通过以下方式生成了一个以2的幂和以2为底的对数的表格:
import math
x = 2.0
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
x = x + x
如何将每个表格完全匹配一个单元格的表格导出到CSV文件中?
参见https://docs.python.org/2/library/csv.html#csv.writer
import math
import csv
x = 2.0
with open('out.csv', 'wb') as f:
writer = csv.writer(f, delimiter=',')
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
writer.writerow([x, math.log(x)/math.log(2)])
x = x + x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.