1.csv相关函数
1.1 csv.reader()
在书上并没有添加b标志参数,这里先不涉及,我们先讨论返回值
import csv
filename = 'data/sitka_weather_07-2018_simple.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
print(header_row)
返回值是\(reader\)对象,这里的\(next()\)函数主要返回\(reader\)读取的下一行,返回值是一个以字符串为元素的列表(默认).如果我们用\(for\)循环遍历\(reader\)默认也是返回以字符串为元素的列表(默认)
for line in reader:
print(line)
返回值,只列部分.
['USW00025333', 'SITKA AIRPORT, AK US', '2018-07-01', '0.25', '', '62', '50']
['USW00025333', 'SITKA AIRPORT, AK US', '2018-07-02', '0.01', '', '58', '53']
['USW00025333', 'SITKA AIRPORT, AK US', '2018-07-03', '0.00', '', '70', '54']
标签:07,返回值,16,AIRPORT,2018,reader,相关,csv,下载
From: https://www.cnblogs.com/newblg/p/16914732.html