title: Add new column to grouped object in python pandas
body: <p>I am trying to do the following: 
  I have a data frame consisting of four columns. I group the frame by column0, then call a function on the grouped object to add an additional column in each group. However, when I try calling the function on the grouped object, I get an Error. My code looks like this:</p>
  
  <pre><code>def function(x):
      return x['column2']-x['column1']
  
  
  Groupeddf = df.groupby('column0')
  for key, group in Groupeddf: 
      Nullgroup=group[group.column3 == 0]
      Nullgroup['new_column']=Nullgroup.apply(function, axis=1)
  </code></pre>
  
  <p>When I try the code, I get <code>ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series</code></p>
  
  <p>My data frame is of the following type:</p>
  
  <pre><code>    column0  column1  column2  column3
  0     a         2        5       1
  1     a         3        7       0
  2     b         1        3       4
  3     c         3        5       0
  </code></pre>
  
  <p>Does anyone have an idea how to fix this?</p>