docstr: Apply function to each column, by group
  Assumes that the dataframe already has a proper index
docstr_tok: ["Apply","function","to","each","column",",","by","group","Assumes","that","the","dataframe","already","has","a","proper","index"]
code: def transform_dataframe(self, dataframe, function, level=0, **kwargs):
      """Apply function to each column, by group
      Assumes that the dataframe already has a proper index"""
      if dataframe.shape[0] != self.nobs:
          raise Exception(
              "dataframe does not have the same shape as index"
          )
      out = dataframe.groupby(level=level).apply(function, **kwargs)
      if 1 in out.shape:
          return np.ravel(out)
      else:
          return np.array(out)
  
imports: from statsmodels.compat.python import lrange, lzip
  import numpy
  import pandas
  import statsmodels.tools.data
  from pandas import Index, MultiIndex
label_desc: Use image node_id 11 for calling the Grouping obj's underlying member method code with example usage: obj.transform_dataframe(dataframe, function, level) and returns: np, np