Python Forum
df.str.contains() Not Working
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
df.str.contains() Not Working
#2
[Update] - Set is Solved.

I realized that I just had to put * in front of each '\d' regex pattern in the below code. For anyone wanting to know the solution, below is the working code:

if "1.4.25" in df.values:
    if "1.4.24" in df.values:
        df = df.set_index("identifier")
        t1i4Level24 = df["1.4.24":"1.4.25"]
        t1i4Level24 = t1i4Level24[:-1]
        t1i4Level24 = t1i4Level24.reset_index(level=['identifier'])
        t1i4Level24 = t1i4Level24[~t1i4Level24.identifier.str.contains(fromMatch_Subjob)]
        countRows = t1i4Level24.identifier.count()
        countRows = countRows - 1
        countRows = countRows.astype(float)
        S_t1i4Level24 = t1i4Level24['%complete'].sum()
        P_t1i4Level24 = S_t1i4Level24 / countRows
        df.at['1.4.24', '%complete']=P_t1i4Level24
        df = df.reset_index(level=['identifier'])
    else:
        pass
else:
    if "1.4.24" in df.values:
        df = df.set_index("identifier")
        loct1i4Level24 = df.loc['1.4.24':, :]
        loct1i4Level24 = loct1i4Level24.reset_index(level=['identifier'])
        tempdf = loct1i4Level24[loct1i4Level24['identifier'].str.contains(r'^\d*'+'.'+'\d*'+'.'+'\d*$')]
        print(tempdf)
Reply


Messages In This Thread
df.str.contains() Not Working - by ahmedwaqas92 - Feb-05-2020, 04:50 AM
RE: df.str.contains() Not Working - by ahmedwaqas92 - Feb-05-2020, 06:51 AM

Forum Jump:

User Panel Messages

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