Aggregating a dataframe to give the sum of values
<p>I tried to group data based on multiple fields but the groupby is not coming in a perfect dataframe</p>

<pre><code>Comgroup Cd Geo IMT Best Remit Name Q1  Q2  Q3  Q4  Total
IT Product  AP  ANZ AVNET   0   0   0   823.09  823.09
IT Product  AG  ANZ TOSHIBA 0   0   5065.4  237060.72   242126.12
IT Product  EMEA    ANZ LENOVO  126664.47   0   0   113285.78   239950.25
IT Product  AP  ANZ LENOVO  196154.85   0   1122.15 10252.13    207529.13
</code></pre>

<p>I wrote the code as below and was the grouping has come in a totally different pattern. </p>

<pre><code>f = {'Q1':['sum'] , 'Q2':['sum'] , 'Q3':['sum'] , 'Q4':['sum'], 'Total':['sum']} 
total_spendfinal = total_spendfinal.groupby(['Geo','IMT','Spend Type','Spend List']).agg(f)
</code></pre>

<p><a href="https://i.stack.imgur.com/TjFNx.jpg" rel="nofollow">Image</a> of how the dataframe looks like is attached. </p>

<p>Need to do total_spendfinal.reset_index(inplace=True) </p>

python pandas dataframe