csv python中最大的行数可以处理? [英] Largest number of rows in a csv python can handle?

查看:1625
本文介绍了csv python中最大的行数可以处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import csv
with open("C:\Anaconda3\FalkParameters\AllModels.csv","r") as f:
    reader = csv.reader(f)
    listofModels = list(reader)

AllModels是一个巨大的csv文件(2.4 GB)。我不知道有多少行,因为我无法用任何应用程序打开它(记事本,记事本++,Excel等)。

AllModels is a huge csv file (2.4 GB). I am not sure how many rows are in there, because I can't open it with any application (notepad, notepad++, excel, etc.).

上面的代码运行okay,但如果我尝试打印listofModels,控制台开始打印,但在某些时候,我得到一个ValueError:I / O操作关闭文件。

The code above runs okay, but if I try to print "listofModels", the console starts printing, but at some point I get a "ValueError: I/O operation on closed file". Printing stops at different rows each time.

我想知道是否有办法处理python中的大量csv文件。

I was wondering if there is a way I can deal with huge csv files in python.

推荐答案

不要将其转换为列表。而是使用generator。
一次打印一个值/行。

Don't convert it to list. Rather use generator instead. print one value/line at a time.

for line in reader:
    print line

希望这有助!

这篇关于csv python中最大的行数可以处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆