此问题在此处已有答案:
only reading first N rows of csv file with csv reader in python(3个答案)
昨天关门了。
我试图从一个大的CSV文件中读取一些数据的子集,我已经尝试使用nrows,但它返回以下错误消息,'TypeError:“nrows”是此函数“”的无效关键字参数,不确定如何更正。
with open('file.csv') as csv_file:
csv_reader = reader(csv_file, nrows=350)
lines = list(csv_reader)
print(lines)
#Aim was to print 350 rows in a list of lists
TypeError: 'nrows' is an invalid keyword argument for this function
1条答案
按热度按时间polkgigr1#
例如,您可以使用
itertools.islice
从csv_reader
中只读取350行: