def format_output(data: pd.DataFrame, source, col_maps=None) -> pd.DataFrame:
if data.empty: return pd.DataFrame()<EOL>if source == '<STR_LIT>': req_cols = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT:value>']<EOL>else: req_cols = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT:name>', '<STR_LIT:value>', '<STR_LIT>']<EOL>if any(col not in data for col in req_cols): return pd.DataFrame()<EOL>if data.dropna(subset=['<STR_LIT:value>']).empty: return pd.DataFrame()<EOL>if source == '<STR_LIT>':<EOL><INDENT>res = pd.DataFrame(pd.concat([<EOL>pd.Series({**{'<STR_LIT>': t}, **grp.set_index('<STR_LIT>').value.to_dict()})<EOL>for t, grp in data.groupby('<STR_LIT>')<EOL>], axis=<NUM_LIT:1>, sort=False)).transpose().set_index('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>res = pd.DataFrame(pd.concat([<EOL>grp.loc[:, ['<STR_LIT:name>', '<STR_LIT:value>']].set_index('<STR_LIT:name>')<EOL>.transpose().reset_index(drop=True).assign(ticker=t)<EOL>for (t, _), grp in data.groupby(['<STR_LIT>', '<STR_LIT>'])<EOL>], sort=False)).reset_index(drop=True).set_index('<STR_LIT>')<EOL>res.columns.name = None<EOL><DEDENT>if col_maps is None: col_maps = dict()<EOL>return res.rename(<EOL>columns=lambda vv: col_maps.get(<EOL>vv, vv.lower().replace('<STR_LIT:U+0020>', '<STR_LIT:_>').replace('<STR_LIT:->', '<STR_LIT:_>')<EOL>)<EOL>).apply(pd.to_numeric, errors='<STR_LIT:ignore>', downcast='<STR_LIT:float>')<EOL>
Format `pdblp` outputs to column-based results

Args:
    data: `pdblp` result
    source: `bdp` or `bds`
    col_maps: rename columns with these mappings

Returns:
    pd.DataFrame

Examples:
    >>> format_output(
    ...     data=pd.read_pickle('xbbg/tests/data/sample_bdp.pkl'),
    ...     source='bdp'
    ... ).reset_index()
              ticker                        name
    0  QQQ US Equity  INVESCO QQQ TRUST SERIES 1
    1  SPY US Equity      SPDR S&P 500 ETF TRUST
    >>> format_output(
    ...     data=pd.read_pickle('xbbg/tests/data/sample_dvd.pkl'),
    ...     source='bds', col_maps={'Dividend Frequency': 'dvd_freq'}
    ... ).loc[:, ['ex_date', 'dividend_amount', 'dvd_freq']].reset_index()
            ticker     ex_date  dividend_amount dvd_freq
    0  C US Equity  2018-02-02             0.32  Quarter