there is this pandas DataFrame with values close to 1 and close to 0:
df = pd.DataFrame({
'colA': (0.97, 0.88, 0.03, 0.02),
'colB': (0.01, 0.03, 0.87, 0.99),
})
Sorting it according to values gives (sorting forcolB has obviously no effect):
df.sort_values(['colA','colB'], ascending=False)
>> colA colB
>> 0 0.97 0.01
>> 1 0.88 0.03
>> 2 0.03 0.87
>> 3 0.02 0.99
However, I would like to sort based on only the larger values, say > 0.5. This would ignore the smaller values for colA and switch to colB for further sorting.
The sorted DataFrame would look like this (row 2 and 3 are switched):
df.some_function(['colA','colB'], ascending=False, condition=i>0.5)
>> colA colB
>> 0 0.97 0.01
>> 1 0.88 0.03
>> 2 0.02 0.99
>> 3 0.03 0.87
Thanks so much for your help!