I have a data file from an instrument that outputs as a CSV. Reading the file and the corresponding columns are no issue, however, due to a slight change in instrumentation, the data file has changed and I'm not sure how to change my code to still read the file.
f = open('Rotator_050816.dat')
lines = f.readlines()
i = 0
while (lines[i]<>"[Data]\n"):
i+=1
i = i + 2
Temp = []; Field = []; Resistance1 = []; Resistance2 = [];
while(i<len(lines)):
data = lines[i].split(",")
Temp.append(float(data[3])
Field.append(float(data[4])
Resistance1.append(float[12])
Resistance2.append(float[13])
i+=1
Temp = np.array(Temp)
Field_T = np.array(Field)/10000.
Resistance1 = np.array(Resistance1)
Excitation1 = np.array(Excitation1)
This is a MWE from previous usage. This has no issue if the CSV file has no blank entries, however, if there are blank entries it presents a problem as then len(Resistance1) ≠ len(Temp) so they cannot be plotted correctly. So my data file now looks like this:
So I need to add lines of code that can read if a row for Res. Ch1 or Res. Ch2 is empty, and then skip that entire row for all variables before appending to the final set of data. This way len(Resistance1) = len(Temp) and each Res. Ch1 measurement matches up to the right Temperature.