def write_xlsx(data, fname, sheet_names=None):
    logger.debug('data: %s')
    if not isinstance(data, collections.Mapping):
        try:
            logger.debug('attempting to construct pd.DataFrame from data')
            dfs = {'Sheet 1' : pd.DataFrame(data)}
        except:
            logger.debug('exception while constructing pd.DataFrame, checking for sequence')
            if isinstance(data, collections.Sequence):
                logger.debug('constructing dict from sequence')
                if sheet_names is not None:
                    assert len(sheet_names) == len(data), 'sheet_names must have the same length as the `dfs` Sequence'
                else:
                    sheet_names = ['Sheet %d' % i for i in range(len(data))]
                dfs = dict(zip(sheet_names, data))
            else:
                dfs = data
    else:
        dfs = data
    assert isinstance(dfs, collections.Mapping), 'type: %s, dfs: %s' % (type(dfs), dfs)

    writer = pd.ExcelWriter(fname)
    for sheet_name, df in dfs.items():
        try:
            df = pd.DataFrame(df)
        except:
            logger.exception('could not convert data object: %s into pandas.DataFrame', df)
        df.to_excel(writer, sheet_name, index=False)
    writer.save()
dataset/ETHPy150Open embr/gcat/gcat/__init__.py/write_xlsx/original