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
Post a Comment