I have this piece of code:
with open(filepath, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=' ')
for row in reader:
print(' '.join(row))
and it returns:
Type,UniProt ID,Position
Sodium channel,P35498,1-123
Sodium channel,P35498,176-188
Sodium channel,P35498,234-239
Sodium channel,P35498,426-762
Sodium channel,P35498,823-830
Potassium channel ATP-sensitive inward rectifier,P48048,1-77
I would like to be able to put P35498 in a string to use later. How would I do this? I would also like to be able to get any of those columns but just an example with P35498 would be great, thanks!
If I do
with open(filepath, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
idlist = []
for row in reader:
idlist.append(row[1])
print(idlist)
This is returned:
['UniProt ID']
['UniProt ID', 'P35498']
['UniProt ID', 'P35498', 'P35498']
['UniProt ID', 'P35498', 'P35498', 'P35498']
['UniProt ID', 'P35498', 'P35498', 'P35498', 'P35498']
['UniProt ID', 'P35498', 'P35498', 'P35498', 'P35498', 'P35498']
['UniProt ID', 'P35498', 'P35498', 'P35498', 'P35498', 'P35498', 'P48048']
p35498