<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collapse_witnesses(self):
 """Groups together witnesses for the same n-gram and work that has the same count, and outputs a single row for each group. This output replaces the siglum field with a sigla field that provides a comma separated list of the witness sigla. Due to this, it is not necessarily possible to run other Results methods on results that have had their witnesses collapsed. """

        # In order to allow for additional columns to be present in
        # the input data (such as label count), copy the siglum
        # information into a new final column, then put the sigla
        # information into the siglum field and finally rename it.
        #
        # This means that in merge_sigla below, the column names are
        # reversed from what would be expected.
        if self._matches.empty:
            self._matches.rename(columns={constants.SIGLUM_FIELDNAME:
                                          constants.SIGLA_FIELDNAME},
                                 inplace=True)
            return
        self._matches.loc[:, constants.SIGLA_FIELDNAME] = \
            self._matches[constants.SIGLUM_FIELDNAME]
        # This code makes the not unwarranted assumption that the same
        # n-gram means the same size and that the same work means the
        # same label.
        grouped = self._matches.groupby(
            [constants.WORK_FIELDNAME, constants.NGRAM_FIELDNAME,
             constants.COUNT_FIELDNAME], sort=False)

        def merge_sigla(df):
            # Take the first result row; only the siglum should differ
            # between them, and there may only be one row.
            merged = df[0:1]
            sigla = list(df[constants.SIGLA_FIELDNAME])
            sigla.sort()
            merged[constants.SIGLUM_FIELDNAME] = ', '.join(sigla)
            return merged

        self._matches = grouped.apply(merge_sigla)
        del self._matches[constants.SIGLA_FIELDNAME]
        self._matches.rename(columns={constants.SIGLUM_FIELDNAME:
                                      constants.SIGLA_FIELDNAME},
                             inplace=True)