This is a test version of Biostars. For the public version, visit https://www.biostars.org.
loop string set

There seems to be something wrong with the code below; im not sure if it is the indentations because im getting a different result each time if i change the indents; I'm not sure which is the correct way to indent.

 fh = open("df_1.csv")
 readr = csv.reader(fh) 
 header = next(readr)
 header
 data = [row for row in readr]
 names = set()
  for row in data : 
   mapID = row[1]
     for n in mapID :
    names.add(n) 
 len(names)
python stringset

This isn't really a bioinformatics question, but we can't really answer the question regardless without understanding what your input and desired output look likes.

im trying to get the number of genes (names). the desired output is a number. input is a csv file.

The number of unique gene names? And the names are in the second column of the CSV file?

yes that is correct

You can just do something like this then.

fh = open("df_1.csv")
readr = csv.reader(fh) 
header = next(readr)
header
data = [row for row in readr]

names = set(x[1] for x in data)
len(names)

0 answers

No answers yet.

Log in to answer this question.