Currently I'm returning column name of the max value in the each row.
df['Active'] = df.idxmax(axis=1)
How do I take into account the Priority for each column? e.g. for Row 0, the Active column should have opC since it has a higher priority than opA. (Also Priority row shouldn't return anything in the Active column).
Update: Follow up scenario. Adding an additional row called 'minOccurrence'. Here's an example of it. Since opD doesn't have 3 straight "Actives" it isn't active at index 1 or 2 where previously it was Active based on 'Priority' column only.
df1 = pd.DataFrame({'opA': [1,1,1,1,0],
'opB': [1,1,1,0,1],
'opC': [1,1,1,1,2],
'opD': [0,1,1,0,3],
'Active': ['opC','opD', 'opD', 'opC', 0]})
df1 = df1.rename(index={df1.last_valid_index() : 'Priority'})
df1.loc['Priority','Active'] = ''
print(df1)
df1 = pd.DataFrame({'opA': [1,1,1,1,0,0],
'opB': [1,1,1,0,1,0],
'opC': [1,1,1,1,2,0],
'opD': [0,1,1,0,3,3],
'Active': ['opC','opC', 'opC', 'opC', 0,0]})
df1 = df1.rename(index={df1.last_valid_index() - 1 : 'Priority'})
df1 = df1.rename(index={df1.last_valid_index() : 'minOccurrence'})
df1.loc['Priority','Active'] = ''
df1.loc['minOccurrence','Active'] = ''
print(df1)
vs. if opD had a 1 at index 0.
df1 = pd.DataFrame({'opA': [1,1,1,1,0,0],
'opB': [1,1,1,0,1,0],
'opC': [1,1,1,1,2,0],
'opD': [1,1,1,0,3,3],
'Active': ['opD','opD', 'opD', 'opC', 0,0]})
df1 = df1.rename(index={df1.last_valid_index() - 1 : 'Priority'})
df1 = df1.rename(index={df1.last_valid_index() : 'minOccurrence'})
df1.loc['Priority','Active'] = ''
df1.loc['minOccurrence','Active'] = ''
print(df1)