Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normalize column: sum to 1 [duplicate]

I have a dataframe:

  Time   Weight 
   1       4 
   2       2
   3       1
   4       7

How can I normalize the weight column, so that the sum of the values in the weight column are equal to 1 ?

like image 639
tj judge Avatar asked Apr 30 '26 10:04

tj judge


1 Answers

You can divide each values in the Weight column by sum of all the values in the Weight column,

df['Weight']/df['Weight'].sum()

0    0.285714
1    0.142857
2    0.071429
3    0.500000
Name: Weight, dtype: float64
like image 68
ThePyGuy Avatar answered May 02 '26 00:05

ThePyGuy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!