I have tab-separated file (city-data.txt):
Alabama Montgomery 32.361538 -86.279118
Alaska Juneau 58.301935 -134.41974
Is it possible to read somehow first two columns as strings and last two as floats?
My output should look like this:
[(Alabama,Montgomery,32.36,-86.28),
(Alaska,Juneau,58.30,-134.42)]
I tried:
mylist2=np.genfromtxt(r'city-data.txt', delimiter='\t', dtype=("<S15","
<S15", float, float)).tolist()
Which gives me first two columns in byte type:
[(b'Alabama', b'Montgomery', 32.361538, -86.279118),
(b'Alaska', b'Juneau', 58.301935, -134.41974)]
I also tried:
with open('city-data.txt') as f:
mylist = [tuple(i.strip().split('\t')) for i in f]
Which gives me all columns in string type:
[('Alabama', 'Montgomery', '32.361538', '-86.279118'),
('Alaska', 'Juneau', '58.301935', '-134.41974')]
I can't come up with any idea how to implement what I need...