python处理csv文件--基础

读取数据:

import csv

csvfile=csv.reader(open("/Users/ss/Desktop/test.csv",'rb'))
for row in csvfile:
    parameterStr = ','.join(row)
    parameters = parameterStr.split(',')


写入数据

import csv
with open('D:/mystuff/33.csv', mode='w') as csvfile:
    #w1=csv.writer(csvfile,delimiter=' ',quotechar="|",quoting=csv.QUOTE_MINIMAL)
    w1=csv.writer(csvfile,dialect='excel')
    w1.writerow(['1','2','3','4'])
    w1.writerow(['11','22','33','44'])
    w1.writerow(["chenfenping","","",""])

import csv
 
writer=csv.writer(open('test.csv', 'wb'))
writer.writerow(['col1', 'col2', 'col3'])
data=[range(3) for i in range(3)]
for item in data:
    writer.writerow(item)

资料:

https://docs.python.org/2/library/csv.html

http://www.360doc.com/content/14/0707/10/16740871_392565773.shtml

阅读更多
版权声明:本文为博主原创文章,转载请注明来源 https://blog.csdn.net/Dolphin_h/article/details/52346561
个人分类: python笔记
上一篇ubuntu上安装elasticsearch遇到的坑
下一篇adb显示当前打开的activity
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭