I have a .csv file containing 3 columns of data. I need to create a new output file that includes a specific set of data from the first and third column from the original file. The third column contains decimal values, and I believe in such a case I have use the float() feature of python. I have tried the following code:
in_file = open("filename.csv", "r") out_file = open("output.csv", "w") while True: line = in_file.readline() if (line == ''): break line = line.strip() items = line.split(',') gi_name = items[0] if (gi_name.startswith("_")) continue p_value = float(items[2]) if (p_value > 0.05): continue out_file.write(','.join([gene_name, str(p_value)])) in_file.close() out_file.close() when I run the above, I recieve the following error:
Error: invalid literal for float(): 0.000001
the value 0.0000001 is the first value in my data set for the third column, and I guess the code cannot read beyond that set but I'm not sure why. I am new to python, and don't really understand why I am getting this error or how to fix it. I have tried other modifications for how to input the float(), but without success. Does anyone know how I might be able to fix this?
csvmodule?