Group By a Column and Sum contents of another column with Python
<p>I have a dataframe <code>merged_df_energy</code>:</p>
<pre><code>+------------------------+------------------------+------------------------+--------------+
| ACT_TIME_AERATEUR_1_F1 | ACT_TIME_AERATEUR_1_F3 | ACT_TIME_AERATEUR_1_F5 | class_energy |
+------------------------+------------------------+------------------------+--------------+
| 63.333333              | 63.333333              | 63.333333              | low          |
| 0                      | 0                      | 0                      | high         |
| 45.67                  | 0                      | 55.94                  | high         |
| 0                      | 0                      | 23.99                  | low          |
| 0                      | 20                     | 23.99                  | medium       |
+------------------------+------------------------+------------------------+--------------+
</code></pre>
<p>I would like to create for each <code>ACT_TIME_AERATEUR_1_Fx</code> (<code>ACT_TIME_AERATEUR_1_F1</code>, <code>ACT_TIME_AERATEUR_1_F3</code> and <code>ACT_TIME_AERATEUR_1_F5</code>) a dataframe which contains these columns: <code>class_energy</code> and <code>sum_time</code></p>
<p>For example for the dataframe corresponding to <code>ACT_TIME_AERATEUR_1_F1</code>:</p>
<pre><code>+-----------------+-----------+
|  class_energy   | sum_time  |
+-----------------+-----------+
| low             | 63.333333 |
| medium          | 0         |
| high            | 45.67     |
+-----------------+-----------+
</code></pre>
<p>I thing to do I should use the group by like this:</p>
<pre><code>data.groupby(by=['class_energy'])['sum_time'].sum()
</code></pre>
<p>How can I do this?</p>