3

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 ?

tj judge
  • 626
  • 3
  • 17
  • 1
    Does this answer your question? [Normalize columns of pandas data frame](https://stackoverflow.com/questions/26414913/normalize-columns-of-pandas-data-frame) or [Normalize columns in pandas dataframe](https://stackoverflow.com/q/62664042/15497888) or [Normalize data in pandas](https://stackoverflow.com/q/12525722/15497888) – Henry Ecker Jun 10 '21 at 19:21
  • 1
    The second link is helpful.. cheers @HenryEcker – tj judge Jun 10 '21 at 19:29

1 Answers1

9

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
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45