python读取csv的不同形式

Python (181) 2023-07-02 03:05:42

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

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

importcsv

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

forrowinreader:
print(row)

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

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

importcsv

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

forrowinreader:
print(row)

以上就是python读取csv的两种形式,希望对大家有所帮助。

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

THE END

发表回复