是的,将
csv文件读入
numpy非常慢。代码路径上有很多纯Python。这些天,即使我使用的是纯格式,
numpy我仍然会使用
pandasIO:
>>> import numpy as np, pandas as pd>>> %time d = np.genfromtxt("./test.csv", delimiter=",")CPU times: user 14.5 s, sys: 396 ms, total: 14.9 sWall time: 14.9 s>>> %time d = np.loadtxt("./test.csv", delimiter=",")CPU times: user 25.7 s, sys: 28 ms, total: 25.8 sWall time: 25.8 s>>> %time d = pd.read_csv("./test.csv", delimiter=",").valuesCPU times: user 740 ms, sys: 36 ms, total: 776 msWall time: 780 ms
另外,在这种简单的情况下,您可以使用Joe
Kington在此处写的内容:
>>> %time data = iter_loadtxt("test.csv")CPU times: user 2.84 s, sys: 24 ms, total: 2.86 sWall time: 2.86 s
还有一个Warren
Weckesser的textreader库,以防万一
pandas依赖太重:
>>> import textreader>>> %time d = textreader.readrows("test.csv", float, ",")readrows: numrows = 1500000CPU times: user 1.3 s, sys: 40 ms, total: 1.34 sWall time: 1.34 s
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)