Reputation: 23
In a pandas dataframe, I am trying to find the minimum of different columns that respects a condition in an other column (kind of an SQL WHERE)
MIN = (dataframe[['col_1','col_2','col_3', 'col_4']].min().min())
But i want MIN to be calculated only where 'col_5' == 'YES'
I have tried to find in the forum but i am not managing to merge the 'multiple column min' and the 'conditional min'..
Thank you !
Upvotes: 1
Views: 1164
Reputation: 4459
so you want something like
MIN = dataframe[dataframe['col_5'] == 'YES']['col_1','col_2','col_3', 'col_4'].min().min()
or a more readable version
dataframe_yes = dataframe[dataframe['col_5'] == 'YES']
MIN = dataframe_yes[['col_1','col_2','col_3', 'col_4']].min().min()
Upvotes: 1