Python Forum
panda, excel - script pauses and doesn't continue running, no error message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
panda, excel - script pauses and doesn't continue running, no error message
#1
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".

Output:
.... row 170 done row 177 done row 182 done row 187 done row 188 done row 195 done row 197 done row 199 done row 214 done 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
Reply
#2
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?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding a new column to a Panda Data Frame rsherry8 2 2,123 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  Error in running the Elliott Fitting function shashisourabh 9 5,238 Nov-19-2020, 06:54 PM
Last Post: osvan
  Get error message in a GAN neural network tutorial jdude50 0 1,674 Oct-22-2020, 11:11 PM
Last Post: jdude50
  Series object error message abhaydd 1 4,883 Aug-11-2019, 01:29 AM
Last Post: boring_accountant
  How to filter data using a panda.DateFrame.loc pawlo392 1 2,651 May-27-2019, 08:47 PM
Last Post: michalmonday
  Error Message - Akainu 2 3,279 May-24-2019, 09:09 PM
Last Post: Akainu
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 18,922 May-22-2019, 02:31 PM
Last Post: twinpiques
  do you know a code that will print all correlation values using numpty and panda? crispybluewaffle88 1 2,442 Mar-06-2019, 12:45 PM
Last Post: scidam
  Make panda dataframe output pretty carstenlp 2 2,942 Jan-17-2019, 10:04 AM
Last Post: carstenlp
  Panda Dataframe Rounding Issue ab0217 5 7,256 Nov-06-2018, 10:15 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020