使用Python读取和写入CSV文件
python中本身就自带csv模块,参考在线手册:http://docs.python.org/2/library/csv.html
#!/usr/bin/env python
# -*- coding:utf-8 -*-
imp
with open('egg.csv','rb') as f:
reader = csv.reader(f)
for row in reader:
print row
打印出来是这样的list
#!/usr/bin/env python
# -*- coding:utf-8 -*-
imp
with open('egg2.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
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'])
#!/usr/bin/env python
# -*- coding:utf-8 -*-
imp
with open('egg2.csv', 'wb') as csvfile:
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'])
想用python处理一下csv格式的数据
想统计a的第一例的最小的数,第二列最小值,第三列最大值,且a有几个
同样得到b,c,d,e等
由 图1 得到 图2(最后一列为啊,a,b,c,d,e的个数)
补充:Web开发 , Python ,