''

def group_data(self):

    groups = self.pdf_groupby.split(',')
    newData = []
    data = self.raw_data
    level = 0
    list_fields = self.list_fields
    for field in groups:
        level += 1
        field = field.strip()
        i = 0
        rowlength = len(list_fields)
        while (i < rowlength):
            if (list_fields[i] == field):
                break
            i += 1
        list_fields = (list_fields[0:i] + list_fields[(i + 1):])
        labels = (self.labels[0:i] + self.labels[(i + 1):])
        self.labels = labels
        currentGroup = None
        r = 0
        for row in data:
            if ((r + 1) in self.subheadingList):
                newData.append(row)
                r += 1
            else:
                try:
                    group = row[i]
                    if (group != currentGroup):
                        line = [group]
                        newData.append(line)
                        r += 1
                        currentGroup = group
                        self.subheadingList.append(r)
                        self.subheadingLevel[r] = level
                        for x in range(len(self.subheadingList)):
                            if (self.subheadingList[x] > r):
                                posn = self.subheadingList[x]
                                self.subheadingList[x] = (posn + 1)
                                oldlevel = self.subheadingLevel[posn]
                                del self.subheadingLevel[posn]
                                self.subheadingLevel[(posn + 1)] = oldlevel
                    line = (row[0:i] + row[(i + 1):])
                    newData.append(line)
                    r += 1
                except:
                    newData.append(row)
                    r += 1
        data = newData
        newData = []
    self.list_fields = list_fields
    return data
