python - make ndarray containg string and int -


how make ndarray reading csv file like

12,employed,32,happy,1 21,unemployed,31,poor,0 34,rich,45,unhapppy,0 

note: file can large

output array:

[[12,"employed",32,"happy",1]  [21,"unemployed",31,"poor",0]  [34,"rich",45,"unhapppy",0]] 

while reading csv file using np.genfromtxt(filename,delimiter = ",",dtype = none) make 1-d array of tuples , dtype = int make strings nan

use read_csv first , dataframe.values convert numpy array:

import pandas pd  df = pd.read_csv('file', header=none) print(df)     0           1   2         3  4 0  12    employed  32     happy  1 1  21  unemployed  31      poor  0 2  34        rich  45  unhapppy  0  arr = df.values print(arr) [[12 'employed' 32 'happy' 1]  [21 'unemployed' 31 'poor' 0]  [34 'rich' 45 'unhapppy' 0]] 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -