I have the following df
Array = np.array([[87, 70, 95],
[52, 47, 44],
[44, 97, 94],
[79, 36, 2]])
df_test = pd.DataFrame(Array, columns=['Apple', 'Banana', 'Tomato'],index=[['Joe', 'Steve', 'Wes', 'Jim']])
Which looks like:
Apple Banana Tomato
Joe 87 70 95
Steve 52 47 44
Wes 44 97 94
Jim 79 36 2
I want to compute the share of each expense by line but I do not find. It must look like:
df_test.apply(lambda: x/max(line),axis=2)
and the results would be:
Apple Banana Tomato
Joe 0.35 0.27 0.37
. . . .
But I cannot find the way to compute inside the lambda function the max of each line. Does someone have idea ? Thanks in advance !