1、以列表的形式读取csv数据
编写一个读取 csv 文件的程序:
import csv csvfile = open('./data.csv', 'r') reader = csv.reader(csvfile) for row in reader: print(row)
import csv将导入Python自带的csv模块。
2、以字典的形式读取csv数据
import csv csvfile = open('./data.csv', 'r') reader = csv.DictReader(csvfile) for row in reader: print(row)
以上就是python读取csv的两种形式,希望对大家有所帮助。 更多Python学习指路: python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
查看更多关于python读取csv的不同形式的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did255151