700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > pythonpandas读取csv文件最后一行_使用numpy / pandas在Python中讀取CSV文件的最后N行

pythonpandas读取csv文件最后一行_使用numpy / pandas在Python中讀取CSV文件的最后N行

时间:2018-12-30 18:08:37

相关推荐

pythonpandas读取csv文件最后一行_使用numpy / pandas在Python中讀取CSV文件的最后N行

7

With a small 10 line test file I tried 2 approaches - parse the whole thing and select the last N lines, versus load all lines, but only parse the last N:

使用一個小的10行測試文件,我嘗試了2種方法 - 解析整個事物並選擇最后N行,而不是加載所有行,但只解析最后N:

In [1025]: timeit np.genfromtxt(stack38704949.txt,delimiter=,)[-5:]

1000 loops, best of 3: 741 µs per loop

In [1026]: %%timeit

...: with open(stack38704949.txt, b) as f:

...: lines = f.readlines()

...: np.genfromtxt(lines[-5:],delimiter=,)

1000 loops, best of 3: 378 µs per loop

This was tagged as a duplicate of Efficiently Read last rows of CSV into DataFrame. The accepted answer there used

這被標記為有效地將最后 行CSV讀入DataFrame的副本。那里接受的答案

from collections import deque

and collected the last N lines in that structure. It also u

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。