panda, excel - script pauses and doesn't continue running, no error message - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: panda, excel - script pauses and doesn't continue running, no error message (/thread-14311.html) |
panda, excel - script pauses and doesn't continue running, no error message - william - Nov-24-2018 Hi, I'm having some trouble with a script I created to essentially run down an excel column, and if it found a particular string to replace that string. It runs great... up until something like row 200. I wondered if it was something to do with the memory my system allows python, but I would expect for the program to quit and give me an error message. Nothing like that? I've posted my script below - as you can see it has a number of if statements and the design is to clean up some data (column name is 'culture1') and replace the names of bacteria with cleaner names so they can be categorised more easily. The output is something like this here... it has no error message and the script does not stop running - it just stays on "row 230 done". I'd really appreciate any help you can give me, I'm quite stuck because I've not encountered a problem like this without an error message before! Thanks guys.import pandas as pd i=0 df=pd.read_excel('*location of data*') #insert info while (i < df.shape[0]): t = df.ix[i, 'culture1'] length = -1 if str(type(t))=='<class \'float\'>': i+=1 elif t.find('Coag.neg.Staph.') > length: df.at[[i], ['culture1']] = 'Coag. neg. Staph.' elif t.find('Staph.aureus') > length: df.at[[i], ['culture1']] = 'Staph. Aureus' elif t.find('Enterococcussp.')>length: df.at[[i], ['culture1']] = 'Enterococcus Sp.' elif t.find('Pseud.aeruginosa')>length: df.at[[i], ['culture1']] = 'Pseud. Aeruginosa' elif t.find('Pseudomonas.putida')>length: df.at[[i], ['culture1']] = 'Pseud. Putida' elif t.find('Candida.albicans')>length: df.at[[i], ['culture1']] = 'Candida Albicans' elif t.find('Enterobacter.cloacae')>length: df.at[[i], ['culture1']] = 'Enterobacter Cloacae' elif t.find('Candida.parapsilosis')>length: df.at[[i], ['culture1']] = 'Candida Parapsilosis' elif t.find('Kleb.pneumoniae')>length: df.at[[i], ['culture1']] = 'Kleb. Pneumoniae' elif t.find('Aci.baumanni')>length: df.at[[i], ['culture1']] = 'Aci. baumanni' elif t.find('Candida.glabrata')>length: df.at[[i], ['culture1']] = 'Candida Glabrata' elif t.find('Candida. glabrata')>length: df.at[[i], ['culture1']] = 'Candida Glabrata' elif t.find('Enterococcus.sp.')>length: df.at[[i], ['culture1']] = 'Enterococcus Sp.' elif t.find('VRE')>length: df.at[[i], ['culture1']] = 'VRE' elif t.find('Klebsiella.oxytoca')>length: df.at[[i], ['culture1']] = 'Klebsiella Oxytoca' elif t.find('E\'coccus.faecalis')>length: df.at[[i], ['culture1']] = 'Enterococcus Faecalis' elif t.find('Eggerthellalenta')>length: df.at[[i], ['culture1']] = 'Eggerthella lenta' elif t.find('Enterococcusfaecium')>length: df.at[[i], ['culture1']] = 'Enterococcus Faecium' elif t.find('Corynebacteriumsp.')>length: df.at[[i], ['culture1']] = 'Corynebacterium Sp.' elif t.find('Propionibacteriumsp')>length: df.at[[i], ['culture1']] = 'Cutibacterium acnes' elif t.find('Escherichiacoli')>length: df.at[[i], ['culture1']] = 'Escherichia coli' elif t.find('MRSA')>length: df.at[[i], ['culture1']] = 'MRSA' elif t.find('Candidaalbicans')>length: df.at[[i], ['culture1']] = 'Candida Albicans' elif t.find('strepmitis/oralis')>length: df.at[[i], ['culture1']] = 'Strep. Mitis' elif t.find('Bacillussp.')>length: df.at[[i], ['culture1']] = 'Bacillus sp.' elif t.find('Staph.haemolyticus')>length: df.at[[i], ['culture1']] = 'Staph. Haemolyticus' elif t.find('Staphepidermidis')>length: df.at[[i], ['culture1']] = 'Staph. Epidermidis' elif t.find('E\'coccusfaecalis')>length: df.at[[i], ['culture1']] = 'Enterococcus Faecalis' elif t.find('Klebsiellaoxytoca')>length: df.at[[i], ['culture1']] = 'Klebsiella Oxytoca' elif t.find('Staphschleiferi')>length: df.at[[i], ['culture1']] = 'Staph. Schleiferi' elif t.find('Proteusmirabilis')>length: df.at[[i], ['culture1']] = 'Proteus Mirabilis' elif t.find('Candidaparapsilosis')>length: df.at[[i], ['culture1']] = 'Candida Parapsilosis' elif t.find('Enterobactercloacae')>length: df.at[[i], ['culture1']] = 'Enterobacter Cloacae' elif t.find('Sten.maltophilia')>length: df.at[[i], ['culture1']] = 'Sten. Maltophilia' elif t.find('VancresEnterococci')>length: df.at[[i], ['culture1']] = 'VRE' elif t.find('Burkholderiacepacia')>length: df.at[[i], ['culture1']] = 'Burkholderia cepacia' elif t.find('Brev.vesicularis')>length: df.at[[i], ['culture1']] = 'B. vesicularis' elif t.find('Micrococcussp.')>length: df.at[[i], ['culture1']] = 'Micrococcus sp.' elif t.find('Candidasp.')>length: df.at[[i], ['culture1']] = 'Candida Sp.' elif t.find(':Coag.neg.Staph.')>length: df.at[[i], ['culture1']] = 'Coag. neg. Staph.' elif t.find('Achromobactersp')>length: df.at[[i], ['culture1']] = 'Achromobacter Sp.' elif t.find('Strep.intermedius')>length: df.at[[i], ['culture1']] = 'Strep. Intermedius' elif t.find('Enterob.sakazaki')>length: df.at[[i], ['culture1']] = 'Enterob. Sakazaki' elif t.find('Enterob.aerogenes')>length: df.at[[i], ['culture1']] = 'Enterob. Aerogenes' elif t.find('E.coli')>length: df.at[[i], ['culture1']] = 'Escherichia coli' elif t.find('Str.parasanguinis')>length: df.at[[i], ['culture1']] = 'Strep. Parasanguinis' else: print('row ', i, 'done') i+=1 df.to_excel('*location*', sheet_name='*NAME*') #insert info RE: panda, excel - script pauses and doesn't continue running, no error message - ichabod801 - Nov-24-2018 Well, i is only incremented if t is a float (I would use isinstance(t, float) there) or if none of the text searches trigger. So if one of the text searches triggers, what prevents it from becoming an infinite loop?
|