I have data that is in the below format (in an ASCII file):
363 28 24 94
536 28 24 95
where we have speed, time, lat, long. Time, lat and long values are all codes for the true values. For example a time of 28 corresponds to 2015-02-01, lat of 24 corresponds to a true latitude of -67 etc.
There are many different coded values. Time ranges from 0-28, lat from 0-24 and long from 0-108.
I would like the replace every single one of the 'code' values with their true counterpart and output into a text file. The format of the text file would be speed, true time, true lat, true long.
I have tried doing this by using a dictionary and replace, however replace does not seem to like the fact that I am reading in an array.
I should also mention that the input file with the original format shown above is 79025 lines long and for each line I have to replace 3 values.
This is my current attempt which is not working with error message: AttributeError: 'numpy.ndarray' object has no attribute 'replace'
data=np.genfromtxt('./data/u_edit_2.coords')
time=data[:,[1]]
lat=data[:,[2]]
lon=data[:,[3]]
def replace_all(text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text
reps = {'0':'2015-01-02', '1':'23773', '2':'23774'}
time_new = replace_all(time, reps)
print time_new
Any suggestions would be appreciated, cheers.