我有一个数据框:
Time Weight
1 4
2 2
3 1
4 7
如何规范权重列,使权重列中的值之和等于 1?
最佳答案
您可以将Weight
列中的每个值除以Weight
列中所有值的sum
,
df['Weight']/df['Weight'].sum()
0 0.285714
1 0.142857
2 0.071429
3 0.500000
Name: Weight, dtype: float64
关于python - 规范化列 : sum to 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67927245/