首页 > 编程语言 > 详细

Python Data Visualization Cookbook 2.2.2

时间:2016-11-12 01:30:37      阅读:285      评论:0      收藏:0      [点我收藏+]
 1 import csv
 2 
 3 filename = ch02-data.csv
 4 data = []
 5 
 6 try:
 7     with open(filename) as f://用with语句将数据文件绑定到对象f
 8         reader = csv.reader(f)
 9         header = next(reader)//Python 3.X 用的是next()
10         data = [row for row in reader]
11 except csv.Error as e:
12     print(Error reading CSV file at line %s: %s % (reader.line_num,e) )
13     sys.exit(-1)
14 
15 if header:
16     print(header)
17     print("=======================")
18 for row in data:
19     print(row)

 

Python Data Visualization Cookbook 2.2.2

原文:http://www.cnblogs.com/barrier/p/6055923.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!