#NEWLINE# def transform_dataframe( self , dataframe , function , level = 0 , **kwargs ) : #NEWLINE# #INDENT# 'Apply function to each column, by group\n        Assumes that the dataframe already has a proper index' #NEWLINE# if ( dataframe . shape [ 0 ] != self . nobs ) : #NEWLINE# #INDENT# raise Exception ( 'dataframe does not have the same shape as index' ) #NEWLINE# #UNINDENT# out = dataframe . groupby ( level = level ) . apply ( function , ** kwargs ) #NEWLINE# if ( 1 in out . shape ) : #NEWLINE# #INDENT# return np . ravel ( out ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return np . array ( out )