title: Aggregate over an index in pandas?
body: <p>How can I aggregate (sum) over an index which I intend to map to new values? Basically I have a <code>groupby</code> result by two variables where I want to groupby one variable into larger classes. The following code does this operation on <code>s</code> by mapping the first by-variable but seems too complicating:</p>
  
  <pre><code>import pandas as pd
  
  mapping={1:1, 2:1, 3:3}
  
  s=pd.Series([1]*6, index=pd.MultiIndex.from_arrays([[1,1,2,2,3,3],[1,2,1,2,1,2]]))
  
  x=s.reset_index()
  x["level_0"]=x.level_0.map(mapping)
  
  result=x.groupby(["level_0", "level_1"])[0].sum()
  </code></pre>
  
  <p>Is there a way to write this more concisely?</p>