Feb-05-2020, 04:50 AM
(This post was last modified: Feb-05-2020, 04:50 AM by ahmedwaqas92.)
I have a if/else procedural code that is querying a data frame. I am passing a str.contains() command after the main (else) function, yet it only shows the 'tempdf' as an empty data frame - See below.
When I print the data frame before tempdf, it shows me the values correctly for 'loct1i4Level24' can someone tell me if my str.contains() has some error?
The Code:
if I print loct1i4Level24, it correctly shows as below
When I print the data frame before tempdf, it shows me the values correctly for 'loct1i4Level24' can someone tell me if my str.contains() has some error?
The 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)Data Frame Results:
if I print loct1i4Level24, it correctly shows as below
identifier taskname %complete 0 1.4.24 Level 24 0.00 1 1.4.24.1 Job 1 0.56 2 1.4.24.2 Job 2 0.33 3 1.4.24.3 Job 3 0.28 4 1.4.30 Level 30 0.00 5 1.4.30.1 Job 1 0.26 6 1.4.30.2 Job 2 0.41 7 1.4.30.3 Job 3 0.66 8 1.4.30.4 Job 4 0.89But tempdf is showing Empty data frame while based on the code it should only print
identifier taskname %complete 0 1.4.24 Level 24 0.00 4 1.4.30 Level 30 0.00Can anyone help identify the problem with this?