当前位置: 首页 > 图灵资讯 > 行业资讯> python读取csv的不同形式

python读取csv的不同形式

来源:图灵python
时间: 2024-08-14 11:08:05

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的两种形式,希望对大家有所帮助。更多Python学习指导:python基础教程

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