Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Skipping Strings
#1
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File loop curiously skipping files - FIXED mbk34 10 686 Feb-10-2024, 07:08 AM
Last Post: buran
  Trying to understand strings and lists of strings Konstantin23 2 699 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Skipping line in text without Restarting Loop IdMineThat 4 1,433 Apr-05-2022, 04:23 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,704 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  python seems to be skipping lines of code alansandbucket 1 4,088 Jun-22-2021, 01:18 AM
Last Post: Larz60+
  looping for time while skipping a day Staph 2 2,144 Jun-23-2019, 03:33 AM
Last Post: Staph
  Finding multiple strings between the two same strings Slither 1 2,482 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  Skipping Loop blueriver649 4 2,766 Apr-18-2019, 04:11 AM
Last Post: blueriver649
  When I read csv file i am getting b'Skipping line messages GuJu 4 10,285 Mar-07-2019, 11:47 AM
Last Post: GuJu
  For loop question(skipping) jure98 1 2,436 Mar-31-2018, 01:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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