code: def rankedSeries(self, tag, outputFile = None, giveCounts = True, giveRanks = False, greatestFirst = True, pandasMode = True, limitTo = None):
          if giveRanks and giveCounts:
              raise mkException("rankedSeries cannot return counts and ranks only one of giveRanks or giveCounts can be True.")
          seriesDict = {}
          for R in self:
              try:
                  val = R[tag]
              except KeyError:
                  continue
              if not isinstance(val, list):
                  val = [val]
              for entry in val:
                  if limitTo and entry not in limitTo:
                      continue
                  if entry in seriesDict:
                      seriesDict[entry] += 1
                  else:
                      seriesDict[entry] = 1
          seriesList = sorted(seriesDict.items(), key = lambda x: x[1], reverse = greatestFirst)
          if outputFile is not None:
              with open(outputFile, 'w') as f:
                  writer = csv.writer(f, dialect = 'excel')
                  writer.writerow((str(tag), 'count'))
                  writer.writerows(seriesList)
          if giveCounts and not pandasMode:
              return seriesList
          elif giveRanks or pandasMode:
              if not greatestFirst:
                  seriesList.reverse()
              currentRank = 1
              retList = []
              panDict = {'entry' : [], 'count' : [], 'rank' : []}
              try:
                  currentCount = seriesList[0][1]
              except IndexError:
                  pass
              else:
                  for valString, count in seriesList:
                      if currentCount > count:
                          currentRank += 1
                          currentCount = count
                      if pandasMode:
                          panDict['entry'].append(valString)
                          panDict['count'].append(count)
                          panDict['rank'].append(currentRank)
                      else:
                          retList.append((valString, currentRank))
              if not greatestFirst:
                  retList.reverse()
              if pandasMode:
                  return panDict
              else:
                  return retList
          else:
              return [e for e,c in seriesList]