首页 / 知识

python读取csv的不同形式

2023-11-12 12:54:00

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学习教程请关注我们

培训数据形式字典模块

最新内容

相关内容

热门文章

推荐文章

标签云

猜你喜欢