Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string match
#1
Hello,

This is just a portion of the code, I thought I would only cut out what I'm currently working on. This part of the code is inside a for loop that loops through a lot of excel files.

I'm having a problem with line 5, for some reason it only shows False throughout the whole dataframe. I don't have the string names because there's to many of them so I had to create string2 on line 4. This grabs the string out of ws1. Am I not able to use \bstring2\b? I basically want the total number of True statements that show for each string found.


 
   stops2 = pd.read_excel(Hold,usecols = "B,D", skiprows=3,header=None,index=False)
   stops2.columns=['Hold','Name']
   stops3=stops2[stops2.Hold != 'Pace'].sort_values(by=['Name'])
   string2=ws1['A1'].value[28:]
   counts4=stops3['Name'].str.match(r'\bstring2\b').sum()
   z3=counts4
Reply
#2
I figured this
counts4=stops3['Train']==(string2)
counts5=counts4[counts4==1].count()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  if statement string match javiopro 2 1,598 Sep-04-2021, 05:56 PM
Last Post: javiopro
  regex match in a string batchen 4 3,160 Jan-20-2020, 08:48 AM
Last Post: batchen
  How to do String match SriRajesh 2 3,573 Apr-02-2017, 01:31 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

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