Pandas, dataframe and creating an error message in Python
Hi,
I have a function that searches a csv database file for a disease (for example melanoma). The function will then produce a list of gene symbols that match the disease name in the file. However I want to create an error message that will be produced if the disease is not found within the file (for example Epilepsy is not in the database). Currently my code has an if statement that I know does not work, i'm new to Python so i'd really appreciate any help.
disease='melanoma'
input_file="curated_gene_disease_associations.tsv"
def select_disease_df(input_file,disease):
df=pd.read_csv(input_file, sep='\t')
selection=df['diseaseName']==disease
if disease not in df['diseaseName']:
raise Exception("Disease not found in database")
my_list=(df[selection]['geneSymbol']).tolist()
return(my_list)
• 1,967 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Hello Galaxy123!
We believe that this post does not fit the main topic of this site.
Worked out why it wasn't working
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!