有几种方法可以获取pandas数据帧的行数。在
我的问题是:只需知道文件的行数,就可以得到实际的行数吗?如果没有,有什么方法可以在不加载数据帧的情况下找到行数?在
在这种情况下,我可以使行数和行数相同。在
...
s1 = len(df.index) # get the row count.
with open(filename) as f: # open a file and count the lines, actual line count is 6377
for i, l in enumerate(f):
pass
s2 = i + 1 # row count
s2 = s2 - 2 # line count -2
输出:
^{pr2}$
不一定。例如,文件可能有标题,在这种情况下,它将比数据帧多出一行。根据从文件中读取数据帧的方式,还有其他方法可以导致Pandas忽略文件中的行(例如,可以让panda忽略注释行)。在
相关问题 更多 >
编程相关推荐