我有一个3GB的CSV文件,我尝试使用python读取,我需要中位数列。
from numpy import *
def data():
return genfromtxt('All.csv',delimiter=',')
data = data() # This is where it fails already.
med = zeros(len(data[0]))
data = data.T
for i in xrange(len(data)):
m = median(data[i])
med[i] = 1.0/float(m)
print med
我得到的错误是这样的:
Python(1545) malloc: *** mmap(size=16777216) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Traceback (most recent call last):
File "Normalize.py", line 40, in <module>
data = data()
File "Normalize.py", line 39, in data
return genfromtxt('All.csv',delimiter=',')
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/numpy/lib/npyio.py", line 1495, in genfromtxt
for (i, line) in enumerate(itertools.chain([first_line, ], fhd)):
MemoryError
我认为这只是内存不足错误。我正在运行具有4GB ram的64位MacOSX,并且以64位模式编译了numpy和Python。
我该如何解决?我应该尝试仅用于内存管理的分布式方法吗?
谢谢
编辑:也尝试与此,但没有运气...
genfromtxt('All.csv',delimiter=',', dtype=float16)
DIEA
凤凰求蛊
相关分类