title: In pandas is there something like a GroupBy.get_group, but with an optional default value?
body: <p>I've got a DataFrame df, which I've 'groupby'ed.  I'm looking for a function which is similar to get_group(name) except that rather than throwing a KeyError if the name doesn't exist, returns an empty DataFrame (or some other value), similar to how dict.get works:</p>
  
  <pre><code>g = df.groupby('x')
  
  # doesn't work, but would be nice:
  i = g.get_group(1, default=[])
  
  # does work, but is hard to read:
  i = g.obj.take(g.indices.get(1, []), g.axis)
  </code></pre>
  
  <p>Is there already a function which provides this?</p>
  
  <p>Edit:</p>
  
  <p>In many ways, the GroupBy object is represented by a dict (.indicies, .groups), and this 'get with default' functionality was core enough to the concept of a dict that it is included in the Python language itself.  It seemed that if a dict-like thing doesn't have a get with default, maybe I'm not understanding it correctly?  Why would a dict like thing not have a 'get with default'?</p>
  
  <p>An abbreviated example of what I want to do is:</p>
  
  <pre><code>df1_bymid = df1.groupby('mid')
  df2_bymid = df2.groupby('mid')
  
  for mid in set(df1_bymid.groups) | set(df2_bymid.groups) :
      rows1 = df1_bymid.get_group(mid, [])
      rows2 = df1_bymid.get_group(mid, [])
      for row1, row2 in itertools.product(rows1, rows2) :
          yield row1, row2
  </code></pre>
  
  <p>Of course I could creating a function, and I might, it just seemed that if I have to go this far out of my way, maybe I'm not using the GroupBy object the way it was intended:</p>
  
  <pre><code>def get_group(df, name, obj=None, default=None) :
      if obj is None :
          obj = df.obj
  
      try :
          inds = df.indices[name]
      except KeyError, e :
          if default is None :
              raise e
  
          inds = default
  
      return df.obj.take(inds, df.axis)
  </code></pre>