python读取csv的不同形式

python读取csv的不同形式

1、以列表的形式读取csv数据

编写一个读取csv文件的程序:

importcsv

csvfile=open('./data.csv','r')

reader=csv.reader(csvfile)

forrowinreader:

print(row)

importcsv将导入Python自带的csv模块。

2、以字典的形式读取csv数据

importcsv

csvfile=open('./data.csv','r')

reader=csv.DictReader(csvfile)

forrowinreader:

print(row)

以上就是python读取csv的两种形式,希望对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

申请14天超长免费试听资格
获取500G教程资料
姓名
电话
课程
立即申请