0

I have a tsv file that contains the following variables with data below each variable. I want to only put the Drug Name, Description and the Targeted Virus into a dictionary. How do I do that?

Drug Name   Drugbank ID    Description    Indication    Targeted Virus

I have the following code, however it prints all the variables I have into the dictionary. I just want the Drug name, description and the targeted virus

import csv

data = csv.reader(open('flu_results.tsv'),delimiter='\t')

fields = data.next()

for row in data:
    item = dict(zip(fields, row))

    print item
qxz
  • 3,814
  • 1
  • 14
  • 29

1 Answers1

-1

Find the index of interested columns in fields, then populating the corresponding data with that index from row. Then zip them.

OceanBlue
  • 21
  • 3