Python读取导出(写⼊)CSV⽂件
参考资料:
⽣成csv⽂件
import csv
with open('egg.csv', 'wb') as csvfile:
python怎么读csv数据
spamwriter = csv.writer(csvfile,dialect='excel')
spamwriter.writerow(['a', '1', '1', '2', '2'])
spamwriter.writerow(['b', '3', '3', '6', '4'])
spamwriter.writerow(['c', '7', '7', '10', '4'])
spamwriter.writerow(['d', '11','11','11', '1'])
spamwriter.writerow(['e', '12','12','14', '3'])
可以⽤excel打开csv⽂件
提⽰:使⽤python的csv⽣成excel所兼容的csv⽂件的话,主要就是创建writer时的参数时要有dialect=’excel’,就可以了。⽤python读取csv⽂件:
import csv
with open('egg.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print row

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。