hi @bruno29a ,
i modified what you suggested still getting nonetype object was not subscriptable
hi @bruno29a ,
i modified what you suggested still getting nonetype object was not subscriptable
Correct, it does raise a warning, and Iâve been pulling my hair to try to understand why. I assumed that the .at[]
would not, and that is why I wanted to know the difference. Thanks for sharing the link.
In the meantime, I had suppressed the warning as a âworkaroundâ:
import pandas as pd
pd.options.mode.chained_assignment = None #This is to disable the SettingWithCopyWarning warning
Indeed, it has no attribute âseriesâ. The attribute is Series. I hope the issue doesnât raise because you changed the case of the script
Apologies @duristef ,
i changed it.
still getting the same error:
â> âNoneTypeâ object is not subscriptable
if i remove
input_table_1[âETIDâ][i][0:2] in [âCSâ, âCTâ] and input_table_1[âETIDâ][j][0:2] in [âCSâ, âCTâ]
this part it is running with out error.
may we need to modify this line i guess
You probably have âNoneâ values in column âETIDâ
in ETID column some values having empty
Hi @Abhiram ,
OK, then that explains it. Please add these conditions too:
input_table_1['ETID'][i] is not None and input_table_1['ETID'][j] is not None
Add them before the conditions that use input_table_1['ETID']
. For example, add it there:
and input_table_1[âAmountâ][i] == input_table_1[âAmountâ][j] and input_table_1[âETIDâ][i] is not None and input_table_1[âETIDâ][j] is not None and input_table_1[âETIDâ][i] != input_table_1[âETIDâ][j] and input_table_1[âETIDâ][i][0:2] in [âCSâ, âCTâ] and input_table_1[âETIDâ][j][0:2] in [âCSâ, âCTâ] and
So, it should integrate like this:
... and input_table_1['Amount'][i] == input_table_1['Amount'][j] and input_table_1['ETID'][i] is not None and input_table_1['ETID'][j] is not None and input_table_1['ETID'][i] != input_table_1['ETID'][j] and input_table_1['ETID'][i][0:2] in ["CS", "CT"] and input_table_1['ETID'][j][0:2] in ["CS", "CT"] and ...
I was able to reproduce the error message. It definitely happens when 1 of the 2 ETID is empty. If theyâre both empty, itâs not a problem since this rule would be evaluated before the substring:
input_table_1['ETID'][i] != input_table_1['ETID'][j]
But once one of them is empty, it will then skip this rule and evaluate the substring, and thatâs when it fails.
The above modifications solve this issue.
EDIT: BTW, you are not using the latest workflow that I gave, which was
You are using an older version that I gave. Itâs hard to troubleshoot if you are using something different from the latest version.
You should also not paste the error message and then give us a modified script - like when your error message said the issue was on line 15, but lines 14, 15 and 16 were empty lines. All these make it hard to troubleshoot properly.
When I reproduced the error, it told me exactly the correct line of the code where the issue was.
and what about row 16
if output_table_1['Cleared?(Yes/No)'][i] == "Yes": #Row being compared to is already flagged, skip and move on
is it a [i]
or a [j]
? (not really important, itâs only a matter of performance)
You need to set both [i] and [j] to âYesâ as per my workflows (all versions of it do this).
Thatâs done based on your rules, which basically is to set both the Current and the Matching rows to âYesâ, where [i] is the current row, and [j] is the matching row
EDIT: Sorry, I thought it was @Abhiram who asked the question
Just realized that it was @duristef who asked that after re-reading it.
Yes, so based on @Abhiram 's requirements, we need to flag both the current row and the matched row
Yes, thatâs ok with me, but Iâm talking about another line. As you can see, the same condition is checked in two lines (those with the arrows)
for i in range(num_of_rows):
if i == num_of_rows: #Last row, do nothing
break
==> if output_table_1['Cleared?(Yes/No)'][i] == "Yes": #Row is already flagged, skip and move on
continue
for j in range(i+1, num_of_rows): #On to the next rows
==> if output_table_1['Cleared?(Yes/No)'][i] == "Yes": #Row being compared to is already flagged, skip and move on
continue
but if the first condition is met, then the inner loop doesnât even start. On the contrary, if it starts thereâs no need to check the same cell again. Instead, I think that in the inner loop you want to check if output_table_1['Cleared?(Yes/No)'][** j **] == "Yes"
. But itâs really not important, the script works the same, itâs only less efficient
Hi @duristef , yes this is because itâs going through the whole table.
It starts with a row, and then compares with the rest of the rows, and for the sake relating to the code, letâs call the starting row as [i], and then it compares with [i+1] until the end of the table, or until it finds the row that match with some conditions (it only needs to find 1 matched row, hence the âcontinueâ when the if statement is true).
So, letâs say [j] is matched. The other rule is that if a row is already matched, you cannot match it again with another row, so that is why both [i] and [j] are set to âYesâ.
Of course, as the loop is going through the table, at some point [i] will reach [j], meaning that it would have already been flagged previously, and we want to skip that row, so yes, we donât want the inner loop to even start for this, skip to next [i]
Ok, you set output_table_1['Cleared?(Yes/No)'][i]="Yes"
in the inner loop, but even then the second (inner) condition is useless, because you break the loop after you set that cell, so you wonât meet it no more. Instead, it would make sense to check output_table_1[âCleared?(Yes/No)â][ j ]: if itâs a Yes, that means the row has already been processed and can be skipped (but maybe I donât get the ratio of the application)
Sorry for being so stubborn and good night
Hi @duristef , sorry, now I see what you mean. At first, I thought you were asking about the assignment, and then I thought you were asking why we were doing the validation on [i].
Yes, you are correct! The for loop will only run if output_table_1['Cleared?(Yes/No)'][i] != "Yes"
, hereby rendering the check in the loop unnecessary.
And you are correct. This was meant to be output_table_1[âCleared?(Yes/No)â][j] == âYesâ
EDIT: @Abhiram , hereâs the updated version: Row Comparison.knwf (21.7 KB)
You still havenât answered why you are separating Case I into another Python Script node? The problem with doing this is that now you have 2 nodes to maintain and also execution-wise, itâs inefficient as both share some base conditions, meaning they have to be evaluated twice.
Thanks @bruno29a & @duristef the script got working,
just now completed the work and sent to my team for the final confirmation.
I have converted this WF to a non-scripting version, which by happenstance also reduced the complexity from 2 nested loops down to a single loop. As others have suspected, itâs not as pretty though. The key ingredient was using an in-memory H2 database to enable both random row access and recursive table access.
This WF is a direct port of the Python logic shared by @bruno29a in post #116. Iâd like to mention that the two nodes in his WF arenât logically equivalent. In the rearranged snippet, rows that enter the last IF
, right before cases A-H are tested, cannot get tested for case I. Replacing the last ELIF
to an IF
should fix that though.
Rough description of how it works:
cleared="Yes"
via Rule EngineNice one @Thyme . Using a DB Join is definitely an alternative when we want to compare data with multiple rows. The join is doing the loop for you. I just did not have the âThymeâ to explore this. Itâs a 116-posts trying to get this to work for 1 method Rules were changed, rules were added, rules needed clarifications, sample data was changed⌠Just did not have the energy to try something else.
Iâm glad that someone did it that way too.
Yeah, Iâve been following this thread loosely since the beginning. Itâs been quite a ride.
We could definitely let the DB do the case checking for us, but I didnât want to node golf this. Other people need to be able to wrap their head around it after all!
Using an H2 DB is a neat big trick, which been a lot easier to learn than recursive loops. Thank you for showing me that one @bruno29a =)
thanks a lot @Thyme.
But as of now it is working fine with python script node. if required i will use the above workflow also.
Thanks.