python - list to array conversion issue -


i trying convert list array , getting data format issue same. code snippet below:

input

f=open('crime_rates.csv','r') data=f.read() data_row = data.split('\n') print(data_row[0:5]) 

output

['albuquerque,749', 'anaheim,371', 'anchorage,828', 'arlington,503', 'atlanta,1379'] 

next code input

int_crime_rates=[] rows in data_row:     crime_rates=rows.split(',')     int_crime_rates.append(crime_rates) print(int_crime_rates) 

output

[['albuquerque', '749'], ['anaheim', '371'], ['anchorage', '828'], ['arlington', '503'], ['atlanta', '1379']] 

next code input

import numpy np arr=np.array(int_crime_rates) print(arr) 

output

[['albuquerque' '749']  ['anaheim' '371']  ['anchorage' '828']  ['arlington' '503']  ['atlanta' '1379' ]] 

commas missing between elements e.g. expecting below result set

[['albuquerque', '749'],  ['anaheim', '371'],  ['anchorage', '828'],  ['arlington', '503'],  ['atlanta', '1379' ]] 

what removing commas? how retain it?

convert list :-)

newarr = list(map(list, arr)) 

newarr should list with commas.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -