我在Python3中遇到以下错误: 发生异常:AttributeError '_csv.reader'对象没有属性'shape'
import requests
from contextlib import closing
import csv
url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv'
with closing(requests.get(url, stream=True)) as r:
f = (line.decode('utf-8') for line in r.iter_lines())
a = csv.reader(f, delimiter=',', quotechar='"')
for row in a:
print(row)
print(a.shape)
答案 0 :(得分:2)
csv.reader
类型没有.shape
属性。我通常会做这样的事情
a = csv.reader(f, ...)
rows = list(a)
for row in rows:
# ...
print(len(rows))