Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: how to print list without newline 
Python :: sum the contents of a list python 
Python :: pd.loc 
Python :: facebook python 
Python :: matplotlib ax.annotate color of the arrow 
Python :: splitting on basis of regex python 
Python :: scan wifi networke micropython 
Python :: how to change the main diagonal in pandas 
Python :: python get timestamp 2020-04-23T12:00:00Z 
Python :: python os path safe string 
Python :: create a thumbnail from video python 
Python :: rsa decryption 
Python :: matplotlib boxplot change size of outliers 
Python :: inverse box-cox transformation python 
Python :: Python __floordiv__ magic method 
Python :: reverse string python 
Python :: scipy.optimize.curve_fit 3D 
Python :: how to use mtproto proxy for telethon 
Python :: python get image RGB data from URL 
Python :: python zip file 
Python :: python enable pyqt errors 
Python :: python chunk text 
Python :: python square 
Python :: python class with optional arguments 
Python :: numpy sort multidimensional array 
Python :: python datetime make timezone aware 
Python :: numpy concatenate arrays 
Python :: df shape 
Python :: if any number python 
Python :: get legend lables and handles from plot in matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =