Python Forum

Full Version: Skipping Strings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

There is more to this script but I cut out the portion I am currently working on. This is part of a for loop, there're a lot of excel files to loop through.

Where the if statement starts is where I'm having some problems. I get an error stating that its out of bounds because it can't find the string. I have some strings that might not be inside stops3 so, how can I skip over the string if it's not found and continue on to the next string in the loop? I figured this if statement would do the trick maybe I'm writing it incorrectly?


   
   stops2 = pd.read_excel(Hold,usecols = "B,D", skiprows=3,header=None,index=False)
   stops2.columns=['Hold','Name']
   stops3=stops2[stops2.Hold != 'Pace']
   String2=ws1['A1'].value[28:]
   if len(String2) > 0:
     counts4=stops3[stops3['Name']==(String2)]
     counts5=counts4['Name'].value_counts()
     z3=counts5[0]