@staticmethod
def _fix_column_widths(writer, df, sheet_name):
    """
        Find an appropriate width for each column for a given sheet.

        Parameters
        ----------
        writer : pandas.ExcelWriter
            The object which holds the handle to the Excel spreadsheet file.
        df : pandas.DataFrame
            The data frame of the data we're writing to disk.
        sheet_name : str
            The name of the current sheet.

        Notes
        -----
        Lifted more or less verbatim from https://stackoverflow.com/a/40535454.

        """
    for idx, col in enumerate(df.columns):
        series = df[col]
        max_len = max((series.astype(str).map(len).max(), len(str(series.
            name)))) + 2
        writer.sheets[sheet_name].set_column(idx, idx, max_len)
