loop string set
0
0
Entering edit mode
9 months ago
aj123 ▴ 120

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 • 671 views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

yes that is correct

ADD REPLY
0
Entering edit mode

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)
ADD REPLY

Login before adding your answer.

Traffic: 2009 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6