def _apply_summaries(self):
        """Add all summary rows and columns."""

        def as_frame(r):
            if isinstance(r, pd.Series):
                return r.to_frame()
            else:
                return r

        df = self.data

        if df.index.nlevels > 1:
            raise ValueError(
                "You cannot currently have both summary rows and columns on a "
                "MultiIndex."
            )

        _df = df
        if self.summary_rows:
            rows = pd.concat([agg.apply(_df)
                              for agg in self._cleaned_summary_rows], axis=1).T
            df = pd.concat([df, as_frame(rows)], axis=0)

        if self.summary_cols:
            cols = pd.concat([agg.apply(_df)
                              for agg in self._cleaned_summary_cols], axis=1)
            df = pd.concat([df, as_frame(cols)], axis=1)

        return df
def _apply_summaries ( self ) : def as_frame ( r ) : if isinstance ( r , pd . Series ) : return r . to_frame ( ) else : return r df = self . data if df . index . nlevels > 1 : raise ValueError ( "You cannot currently have both summary rows and columns on a " "MultiIndex." ) _df = df if self . summary_rows : rows = pd . concat ( [ agg . apply ( _df ) for agg in self . _cleaned_summary_rows ] , axis = 1 ) . T df = pd . concat ( [ df , as_frame ( rows ) ] , axis = 0 ) if self . summary_cols : cols = pd . concat ( [ agg . apply ( _df ) for agg in self . _cleaned_summary_cols ] , axis = 1 ) df = pd . concat ( [ df , as_frame ( cols ) ] , axis = 1 ) return df
Add all summary rows and columns.