Is there any convenient way to normalize each row by row's maximum (divide by row's max) eg:
df=
A B C
2 1 1
1 4 1
0 2 1
return:
A B C
1 0.5 0.5
0.25 1 0.25
0 1 0.5
You can use apply
and apply a lambda row-wise:
In [199]:
df.apply(lambda x: x/x.max(), axis=1)
Out[199]:
A B C
0 1.00 0.5 0.50
1 0.25 1.0 0.25
2 0.00 1.0 0.50
You can also use div
:
In [205]:
df.div(df.max(axis=1), axis=0)
Out[205]:
A B C
0 1.00 0.5 0.50
1 0.25 1.0 0.25
2 0.00 1.0 0.50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With