Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas convert string to numpy array

import pandas as pd
import numpy as np

x = str(np.arange(1,100))
df = pd.DataFrame([x,x,x,x])
df.columns = ['words']
print 'sample'
print df.head()
result = df['words'].apply(lambda x: 
                           np.fromstring(
                               x.replace('
','')
                                .replace('[','')
                                .replace(']','')
                                .replace('  ',' '), sep=' '))
print 'result'
print result
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #convert #string #numpy #array
ADD COMMENT
Topic
Name
4+9 =