- Code: Select all
`f = open ('//home//enrique//Desktop//WindCube//WLS7-94_merged_sta_files//WLS7-94_2012_01_02__00_10_00.sta')`

data = [] # Define list

from numpy import * # Open numpy for later data handling

x = True

while x == True: # Read file until you reach 'Altitudes' (get rid of header')

line = f.readline()

Altitudes = line

if str.find(line,'Altitudes') == 0:

x = False

header = f.readline() # Get rid of last line of header

while line: #data starts, read data until the file is over

line = f.readline() #read line by line

delimitador = str.find(line,':') # delimiter to get rid of date when data was collected

data.append(line[delimitador+4:]) #storage each line of data into a list

f.close()

As you can see, I got what matters from the data into a list of objects (basically lines of strings). what I did in MatLab was creating a loop that converts each line to double (str2num) and storages into a matrix, basically transform each line into a vector keeping the same format. I have no idea how to do this in matlab; the approach I am trying to take is to create a cellarray and storage each line as a row. The problem is, I have to convert the str into float. I tried the following:

- Code: Select all
`[float(i) for i in data[1]]`

Tried picking object 1 from the list, but it doesn't work, it says it cant convert str into float. Some of the values into the data are empty or 'NaN', since it is formatted to be read into matlab. So I guess the problem is the 'NaN', is there any way I could get read of the NaN??? I did somthing similar in matlab once using string functions, but I have no clue of how to do it in python .

Help please!!!

Thank you.