I have 50 csv files named with a unique id in a folder. In each of the csv files, there are names and their corresponding scores (out of 100). Now I have to filter the csv sheet based on the score>50 and get the corresponding names in text files named with the unique id just as the csv file from which it was taken and put them in a new folder. The following is the code I have written but the output is not as expected.
import glob, os
os.chdir("path of the folder")
for file in glob.glob("*.csv"):
with open(file,'r') as fin:
next(fin) #skip the header row
for row in csv.reader(fin, delimiter=' '):
for col in csv.reader(row, delimiter=','):
if int(col[1])>50
for i, line in enumerate(fin):
f=open("Path to the new folder/output_%i.txt" %i, 'w')
f.write(col[0])
f.close()
The above code generated one file for each score which lies greater than 50 which i dont want. So I request you to correct the above code to help me get the required output. Thank you in advance.
How is this a bioinformatics question? As presented this is purely a python programming question and should probably be asked elsewhere such as StackOverflow.
You are right. It is not bioinformatics question. I have similar bioinformatics data which I am not suppose to disclose. Hence I have replaced it with different terms.