python怎样读取部分csv文件
1个回答
展开全部
参考方法如下:
逐行处理:
for line in open("samples/sample.csv"):
title, year, director = line.split(",") //以“,”号为分割,按逗号将数据分成三部分;
print year, title
使用csv模块处理:
import csv
reader = csv.reader(open("samples\sample.csv"))
for title, year, director in reader:
print year, title
改变分隔符;
逐行处理:
for line in open("samples/sample.csv"):
title, year, director = line.split(",") //以“,”号为分割,按逗号将数据分成三部分;
print year, title
使用csv模块处理:
import csv
reader = csv.reader(open("samples\sample.csv"))
for title, year, director in reader:
print year, title
改变分隔符;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询