title: How to sum up the columns of a pandas dataframe according to the elements in one of the columns
body: <p>I have a csv file like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>squareid       nofcolumns  callduration
  3959_3_3       3.990301    997.056881
  3961_2_2       7.996370   1153.932142
  3961_2_3_0     5.345003    760.179554
  3961_2_3_1     5.064245   1341.673636
  3961_2_3_2    16.816554   2926.182896
  3961_2_3_3_0   3.116286    351.698031
  3961_2_3_3_1   7.269828   1842.511559
  3961_3_2      10.944895   6865.086506
  3962_0_1_0     3.116931    674.581507
  3962_0_2       8.272328   4330.343234
  3962_0_3       3.079968    279.802874
  3962_1_0_0     4.015021    344.013988
  3962_2_0_1     3.787312   1820.223512
  3962_3_1       4.263979    657.806411
  3962_3_2_2     4.184289    266.976026
  3962_3_3_2     4.797507   1537.279123
  3963_1_3_0     7.594542    545.348282
  3963_1_3_3     3.845666    186.378080
  3963_3_1_2_2   3.350109    505.276355
  3963_3_1_2_3   3.229853    302.434752
  ...
  </code></pre>
  
  <p>I want to aggregate over the two columns of <code>nofcalls</code> and <code>callduration</code> according to the <code>squareid</code> column and write the result file into a new csv file.</p>
  
  <p>What I have tried for this part is:</p>
  
  <pre><code>sub_df = sub_df.groupby('squareid').sum()
  sub_df.to_csv(filename2,sep = '\t',header = False,index = False)
  </code></pre>
  
  <p>The aggregation worked but in the files that are generated the <code>squareid</code> column is missed.</p>
  
  <p>How can I write it like the original file that the <code>squareid</code> column be specified?</p>