找出CSV文件中的行数 [英] finding out the number of rows in a CSV file

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

问题描述

任何人都知道如何找出csv文件中有多少行?


我找不到在csv.reader上执行此操作的方法。


提前致谢

anyone know how I would find out how many rows are in a csv file?

I can''t find a method which does this on csv.reader.

Thanks in advance

推荐答案

8月27日下午12:16,SimonPalmer< simon.pal .. 。@ gmail.comwrote:
On Aug 27, 12:16 pm, SimonPalmer <simon.pal...@gmail.comwrote:

任何人都知道如何找出csv文件中有多少行?


我找不到一个在csv.reader上执行此操作的方法。


预先谢谢
anyone know how I would find out how many rows are in a csv file?

I can''t find a method which does this on csv.reader.

Thanks in advance



你必须迭代每一行并计算它们 - 没有其他方式

没有支持信息(因为每行长度自然是

变量,你甚至无法使用文件大小作为指标)。


类似于:


row_count = sum(csv.reader中的行为1(打开(' 'filename.csv'')))


hth

Jon。

You have to iterate each row and count them -- there''s no other way
without supporting information (since each row length is naturally
variable, you can''t even use the file size as an indicator).

Something like:

row_count = sum(1 for row in csv.reader( open(''filename.csv'') ) )

hth
Jon.


2008/8 / 27 Si monPalmer< si ********** @ gmail.com>:
2008/8/27 SimonPalmer <si**********@gmail.com>:

任何人都知道如何知道csv中有多少行文件?


我找不到在csv.reader上执行此操作的方法。
anyone know how I would find out how many rows are in a csv file?

I can''t find a method which does this on csv.reader.



len(list(csv.reader(open(''my.csv''))))


- -

干杯,

Simon B.
si *** @ brunningonline。网
http://www.brunningonline.net/ simon / blog /


8月27日下午12:29,Simon Brunning < si ... @ brunningonline.net>

写道:
On Aug 27, 12:29 pm, "Simon Brunning" <si...@brunningonline.net>
wrote:

2008/8/27 SimonPalmer< simon.pal .. 。@ gmail.com>:
2008/8/27 SimonPalmer <simon.pal...@gmail.com>:

任何人都知道如何找出csv文件中有多少行?
anyone know how I would find out how many rows are in a csv file?


我找不到在csv.reader上执行此操作的方法。
I can''t find a method which does this on csv.reader.



len(list(csv.reader(open(''my.csv''))))


- -

干杯,

Simon B.

si ... @ brunningonline.nethttp://www.brunningonline.net/simon/blog /


len(list(csv.reader(open(''my.csv''))))

--
Cheers,
Simon B.
si...@brunningonline.nethttp://www.brunningonline.net/simon/blog/



如果行大小或行数很大,这不是最好的想法!

制作一个列表,然后丢弃以获得它长度 - 哎哟!

Not the best of ideas if the row size or number of rows is large!
Manufacture a list, then discard to get its length -- ouch!


这篇关于找出CSV文件中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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