sum columns in dataframe with pandas
<p>I have a dataframe df_F1</p>

<p>df_F1.info()</p>

<pre><code>   &lt;class 'pandas.core.frame.DataFrame'&gt;
    Int64Index: 2 entries, 0 to 1
    Data columns (total 7 columns):
    class_energy              2 non-null object
    ACT_TIME_AERATEUR_1_F1    2 non-null float64
    ACT_TIME_AERATEUR_1_F3    2 non-null float64
    dtypes: float64(6), object(1)
    memory usage: 128.0+ bytes
</code></pre>

<p>df_F1.head()</p>

<pre><code> class_energy ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3   
 low 5.875550 431 
 medium 856.666667 856
</code></pre>

<p>I try to create a dataframe Ratio wich contain for each class_energy the value of energy of each ACT_TIME_AERATEUR_1_Fx devided by the sum of energy of all class_energy for each ACT_TIME_AERATEUR_1_Fx. For example :</p>

<blockquote>
<pre><code>ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3 
low        5.875550/(5.875550 + 856.666667) 431/(431+856) 
medium 856.666667/(5.875550+856.666667) 856/(431+856)
</code></pre>
</blockquote>

<p>Can you help me please to resolve it?</p>

<p>Thank you in advancce</p>

<p>Best regards</p>

<p>you can do this:</p>

<pre><code>In [20]: df.set_index('class_energy').apply(lambda x: x/x.sum()).reset_index()
Out[20]:
  class_energy  ACT_TIME_AERATEUR_1_F1  ACT_TIME_AERATEUR_1_F3
0          low                0.006812                0.334887
1       medium                0.993188                0.665113
</code></pre>

python pandas dataframe sum