code: def groupby(self, keyexpr, **outexprs):
          if isinstance(keyexpr, basestring):
              keyattrs = keyexpr.split()
              keyfn = lambda o: tuple(getattr(o, k) for k in keyattrs)
          elif isinstance(keyexpr, tuple):
              keyattrs = (keyexpr[0],)
              keyfn = keyexpr[1]
          else:
              raise TypeError("keyexpr must be string or tuple")
          groupedobs = defaultdict(list)
          do_all(groupedobs[keyfn(ob)].append(ob) for ob in self.obs)
          tbl = Table()
          do_all(tbl.create_index(k, unique=(len(keyattrs) == 1)) for k in keyattrs)
          for key, recs in sorted(groupedobs.items()):
              groupobj = DataObject(**dict(zip(keyattrs, key)))
              do_all(setattr(groupobj, subkey, expr(recs)) for subkey, expr in outexprs.items())
              tbl.insert(groupobj)
          return tbl