1

I need to find all the combinations of rows where multiple conditions are met. I tried to use the powerset recipe from itertools and the answer here by adding multiple conditions but can't seem to get the conditions to work properly. The code I've come up with is:

def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

df_groups = pd.concat(
                  [data.reindex(l).assign(Group = n) for n, l in 
                   enumerate(powerset(data.index)) ])
                   if ((data.loc[l, 'Account'] == 'COS').any() & (data.loc[l,'Amount'].sum() >= 100)
                        & (data.loc[l,'Account'] == 'Rev').any() & (data.loc[l, 'Amount'].sum() >= 150)
                        & (data.loc[l,'Account'] == 'Inv').any() and (data.loc[l, 'Amount'].sum() >= 60)))] )

What I'm trying to do above is find only those combinations where the the following thresholds are met/exceeded:

Account     Amount
COS         150 
Rev         100 
Inv         60  

Sample data:

Entity  Account Amount  Location
A10      Rev    60       A
B01      Rev    90       B
C11      Rev    80       C
B01      COS    90       B
C11      COS    80       C
A10      Inv    60       A

Apologies in advance for the poor question writing etiquette, its the first time I haven't been able to find an answer on Stackoverflow and have had to ask a question.
Also, aware that this will get very slow as len(data) increases so any suggestions on that end are also greatly appreciated.

Arawan
  • 11
  • 2

0 Answers0