for below dataframe data:
x y a b c
2 6 12 1 2
1 2 4 6 8
I want result in new column(i.e d) that returns name of column with max value only among a,b,c.
cols
a
c
I'm trying to find maximum values from three columns and return column name.But instead of selecting all the rows of dataset,I want to select rows of only these three columns.I'm using the following code:
def returncolname(row, colnames):
return colnames[np.argmax(row.values)]
data['colmax'] = data.apply(lambda x: returncolname(x, data.columns), axis=1)