I have a pandas series, each cell containts a string of ints (same number of ints in each string, seperated by a space), e.g.
s = pd.Series(['1 17 -3 ... n'],['100 -27 344 ... n'],...,['0 14 2 ... n'])
I know how to convert a single cell into a numpy vector:
arr = np.asarray(s[0].split(' '), dtype = np.float32)
I also know how to convert the whole series into a matrix, which is my finel goal:
X = np.zeros((len(s), number_of_ints_in_string))
for i, cell in enumerate(s):
X[i,:] = np.asarray(cell.split(' '), dtype = np.float32)
the problem is that for a very long series (which is my case), this is slow. Is there any faster way to do this?
sexpression don't look right.string.spliton each string. Inpandasthe elements of that Series are Python strings. Even thenp.char.splitfunction uses Python string methods. So there isn't a fasterwhole-arraymethod.