python - Find max value and the corresponding column/index name in entire dataframe -
i want select maximum value in dataframe, , find out index , column name of value. there way it?
say, in example below, want first find max value (31), , return index , column name of value (20, r20d)
a = pd.dataframe({'r05d':[1,2,3],'r10d':[7,4,3],'r20d':[31,2,4]},index=[20,25,30])   thanks!
turn dataframe multipleindex series , ask index of max element argmax or idxmax function:
coord = a.stack().argmax() coord (20, 'r20d')   to value, use coordinates against loc:
df.loc[coord] 31      
Comments
Post a Comment