When I use the following code to load a csv file using numpy
F = np.loadtxt(F,skiprows=1, delimiter=',',usecols=(2,4,6))
MASS = F[:,4]
#print(MASS)
Z = F[:,6]
N = len(MASS)
print(len(MASS))
I get the following error
Traceback (most recent call last):
File "C:\Users\Codes\test2.py", line 16, in <module>
F = np.loadtxt(F,skiprows=1, delimiter=',',usecols=(2,4,6))
File "C:\Python34\lib\site-packages\numpy\lib\npyio.py", line 859, in loadtxt
X.append(items)
MemoryError
I have 24Gb if physical memory and the file is 2.70Gb so I do not understand why I am getting this error. Thanks!
EDIT
I also tried to load the same file like this
f = open(F) #Opens file
f.readline() # Strips Header
nlines = islice(f, N) #slices file to only read N lines
for line in nlines:
if line !='':
line = line.strip()
line = line.replace(',',' ') #Replace comma with space
columns = line.split()
tid = columns[2]
m = columns[4]
r = columns[6] # assigns variable to columns
M.append(m)
R.append(r) #appends data in list
TID.append(tid)
print(len(MASS))
and got another memory error.
Traceback (most recent call last):
File "C:\Users\Loop test.py", line 58, in <module>
M.append(m)
MemoryError
It seems like in this case it is running out of memory when building the first list M