如何获取pandas中连续值的比例?

How to get the proportion of values in a row in pandas?

假设我有以下 df:

col1|col2|col3
  1 |  3 |  1
  2 |  2 |  1

我想要行值的比例,所以 stg 是这样的:

col1|col2|col3
 0.2| 0.6| 0.2
 0.4| 0.4| 0.4

到目前为止,我的主要问题是如何获取行的总和:

mydf["col1_proportion"] = mydf["col1"].apply(lambda x: x / (XXX)  )  

其中 (XXX) 应该是给定行的总和

尝试 divsum

out = df.div(df.sum(1),axis=0)
Out[36]: 
   col1  col2  col3
0   0.2   0.6   0.2
1   0.4   0.4   0.2