# Missing value # Keep these values and replace by NaN for floats and -999 for integers T = [] # Initialize list for temp, distance, angle D = [] A = [] digpos = [2, 15, 23] # List with positions of last digit in fields with open('data_g2.dat','r') as fnum: i = 0 for currline in fnum: twhole = currline # Keep whole string t = currline.strip().split() # strip leading/trailing spaces # and split into list element i = i + 1 imiss = -1 if i > 7: # start inserting with line 8 for j in range(len(digpos)): # Check for missing values # We need to do this on the whole # string, before .strip().split() if twhole[digpos[j]] == ' ': imiss = j # Need to insert missing value into correct place if imiss != -1: tnew = [] for j in range(3): tnew.append(' ') for j in range(3): if j > imiss: tnew[j] = t[j-1] elif j == imiss: if imiss == 0 or imiss == 1: tnew[j] = 'nan' elif imiss == 2: tnew[j] = '-999' elif j < imiss: tnew[j] = t[j] t = tnew T.append(float(t[0])) D.append(float(t[1])) A.append(int(t[2])) print(T) print(D) print(A)