python - loading strings with spaces as numpy array -


i load csv file numpy array. each row contains string fields spaces. tried both loadtxt() , genfromtxt() methods available in numpy. default both methods consider space delimiter , separates each word in string separate column. there anyway load sort of data using loadtxt() or genfromtxt() or have write own code it?

sample row file:

826##25733##emanuele buratti## ##mammalian cell expression

here ## delimiter , space denotes missing values.

i think problem default comments character # conflicting delimiter. able load data this:

>>> import numpy np >>> np.loadtxt('/tmp/sample.txt', dtype=str, delimiter='##', comments=none) array(['826', '25733', 'emanuele buratti', ' ', 'mammalian cell expression'],        dtype='|s25') 

you can see dtype has been automatically set whatever maximum length string was. can use dtype=object if troublesome. aside, since data not numeric, recommend using csv module rather numpy job.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -