[英]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.