string match - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: string match (/thread-28653.html) |
string match - Kristenl2784 - Jul-28-2020 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 RE: string match - Kristenl2784 - Jul-28-2020 I figured this counts4=stops3['Train']==(string2) counts5=counts4[counts4==1].count() |