Wow! Yes, that is exactly what I need! How do I make it run that same thing for the entire document instead of the first five lines?
Help for a python BEGINNER
Please help, I am a python newbie, and I'm trying to figure how to convert a list of about a million ensembl gene ID's into gene symbols. I have imported pandas and numpy and have gotten to the point where I have the csv imported.
data = pd.read_csv("genes_affected_2.csv")
data.head()
I am trying to use a code like this:
ginfo = mg.querymany(ens, scopes='ensembl.gene')
for g in ginfo:
for k, v in g.iteritems():
print "- {0: <10}: {1}".format(k, v)
print
but I can't figure out how to take the column values from the "genes_affected_2.csv" file and convert them.
• 1,757 views
•
link
1 answer
You could use the following example. You want to figure out building a list of genes from what data.head() tells you about column headers.
#!/usr/bin/env python
import sys
from mygene import MyGeneInfo
mg = MyGeneInfo()
genes = [
"ENSG00000099308",
"ENSG00000150676",
"ENSG00000180776",
"ENSG00000108848",
"ENSG00000101473"
]
results = mg.querymany(genes, scopes=["ensembl.gene"], fields=["symbol"], species="human", verbose=False)
for res in results:
q = res['query']
s = 'NA'
if 'symbol' in res:
s = res['symbol']
sys.stdout.write('{}\t{}\n'.format(q, s))
This example gives the response:
$ ./test.py
ENSG00000099308 MAST3
ENSG00000150676 CCDC83
ENSG00000180776 ZDHHC20
ENSG00000108848 LUC7L3
ENSG00000101473 ACOT8
• 0 views
•
link
• 0 views
•
link
I just figured it out! Used the iloc code and a foreloop for the entire table. Thank you so much!!!! Honestly couldn't have done it without your help.
• 0 views
•
link
Log in to answer this question.
What does
data.head()return?It just returns the first five lines of my table!