[问题] 请问 CSV

楼主: lingze (walkman)   2014-03-18 19:37:53
小弟是新手,想写入资料
查询了CSV的用法
import csv
data = [
[' 101/01/31', '5,486,734,180', '162,361,181,834', '1,283,951', '7,517.08',
'109.67'],
[' 101/01/13', '3,497,838,901', '99,286,437,370', '819,762', '7,181.54',
'1'],
]
f = open("stock.csv","w")
w = csv.writer(f)
w.writerows(data)
f.close()
这是在网络上看到的,执行后资料会放成row
如果我想要把DATA放直的(也就是说一个List[] 资料放一个column 要怎么使用呢><?)
作者: tiefblau (tiefblau)   2014-03-18 20:18:00
zip(*data)
楼主: lingze (walkman)   2014-03-18 20:23:00
请问楼上大大ZIP怎么转换@@?办到了~~谢谢大大
作者: tiefblau (tiefblau)   2014-03-18 20:28:00
data = zip(*data) 或是直接w.writerows(zip(*data))
楼主: lingze (walkman)   2014-03-18 20:28:00
谢谢各位大大:D
楼主: lingze (walkman)   2014-03-18 20:31:00
XD

Links booklink

Contact Us: admin [ a t ] ucptt.com