I am trying to write the output of python script to a text file. The script runs for sometime and write the content to the file. But after sometime I get 'PermissionError: [Errno 13] Permission denied:'
Below is my script.
def ancestor_map(id):
row_icd = umls[umls['AUI'] == id]
cui = row_icd.CUI.to_string(index=False)
if cui in df_mdr_pt_llt['CUI'].values:
match = df_mdr_pt_llt[df_mdr_pt_llt['CUI'] == cui]
match = match[["CODE", "STR", "TTY", "SDUI"]].drop_duplicates()
match["icd_code"] = icd_code
match["icd_term"] = icd_term
match["level"] = level
match["is_a"] = 'indirect_rel'
match = match.loc[:, ["icd_code","icd_term","CODE","STR", "TTY", "SDUI", "level", "is_a"]]
match.to_csv(r'indirect_mapping_icd10cm.txt', header=None, index=None, sep='\t', mode='a')
else:
print ('match not found: continue')
How can I modify my script to write the whole content without any error.
Any help is highly appreciated!