I'm struggling with getting string values into an array in python. I have a file, about 30k entries long, and each row looks like this:
0R1,Sn=0.3M,Sm=0.7M,Sx=1.5M
I don't need the 0R1 part; all I need is all the Sn values in one array, the Sm values in another, and the Sx in another (of course, I haven't figured out how I'm going to get the numerical values out of the string yet, but I'll think about that later). Right now I'm trying to make an array of strings, I suppose.
Here's my code:
fname = '\\pathname...\\WXT51003.txt'
f1 = open(fname, 'r')
import csv
import numpy
from numpy import zeros
reader = csv.reader(f1)
Max = zeros((29697,1), dtype = numpy.str)
Mean = zeros((29697,1), dtype = numpy.str)
Min = zeros((29697,1), dtype = numpy.str)
for i, row in enumerate(reader):
Min[i] = row[1]
Mean[i] = row[2]
Max[i] = row[3]
f1.close()
print Min[0:10]
The output of the print statement is an array with 'S' in every row. How do I get it to read the entire string, and not just the first character?