Glenn Jones
April 25th, 2009, 05:00 PM
First off apologies if this has been covered before.
So I recently decided to move away from matlab to scientific python for various reasons. I've had a lot of success up to now particularly with plotting various data using matplotlib.
I would however like to learn more vanilla python and hence my question.
I have a file I wish to open with have integers separated by a tabs e.g.
19970426 4
19970417 304
19970417 308
19970423 55
19970423 61
19970427 222
I have managed to use python to open the file and print the data using the following:
f=open('file_path', 'r')
data=[line.strip() for line in f.readlines()]
and data looks like
In [35]: data
Out[35]:
['19970426\t 4',
'19970417\t304',
'19970417\t308',
'19970423\t 55',
'19970423\t 61',
'19970427\t222']
what I would like is to do is to convert data to integer array e.g.
data[0,:]=
[19970426,
19970417,
19970417,
19970423,
19970427]
data[1,:]=
[4,
304,
308,
55,
61,
222]
How do I do this? i.e. how do I manipulate the string?
Thanks
Glenn
So I recently decided to move away from matlab to scientific python for various reasons. I've had a lot of success up to now particularly with plotting various data using matplotlib.
I would however like to learn more vanilla python and hence my question.
I have a file I wish to open with have integers separated by a tabs e.g.
19970426 4
19970417 304
19970417 308
19970423 55
19970423 61
19970427 222
I have managed to use python to open the file and print the data using the following:
f=open('file_path', 'r')
data=[line.strip() for line in f.readlines()]
and data looks like
In [35]: data
Out[35]:
['19970426\t 4',
'19970417\t304',
'19970417\t308',
'19970423\t 55',
'19970423\t 61',
'19970427\t222']
what I would like is to do is to convert data to integer array e.g.
data[0,:]=
[19970426,
19970417,
19970417,
19970423,
19970427]
data[1,:]=
[4,
304,
308,
55,
61,
222]
How do I do this? i.e. how do I manipulate the string?
Thanks
Glenn