<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rankedSeries(self, tag, outputFile = None, giveCounts = True, giveRanks = False, greatestFirst = True, pandasMode = True, limitTo = None):
 """Creates an pandas dict of the ordered list of all the values of _tag_, with and ranked by their number of occurrences. A list can also be returned with the the counts or ranks added or it can be written to a file. # Parameters _tag_ : `str` > The tag to be ranked _outputFile_ : `optional str` > A file path to write a csv with 2 columns, one the tag values the other their counts _giveCounts_ : `optional bool` > Default `True`, if `True` the retuned list will be composed of tuples the first values being the tag value and the second their counts. This supersedes _giveRanks_. _giveRanks_ : `optional bool` > Default `False`, if `True` and _giveCounts_ is `False`, the retuned list will be composed of tuples the first values being the tag value and the second their ranks. This is superseded by _giveCounts_. _greatestFirst_ : `optional bool` > Default `True`, if `True` the returned list will be ordered with the highest ranked value first, otherwise the lowest ranked will be first. _pandasMode_ : `optional bool` > Default `True`, if `True` a `dict` ready for pandas will be returned, otherwise a list _limitTo_ : `optional list[values]` > Default `None`, if a list is provided only those values in the list will be counted or returned # Returns `dict[str:list[value]] or list[str]` > A `dict` or `list` will be returned depending on if _pandasMode_ is `True` """

        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:
            #This should be faster than using get, since get is a wrapper for __getitem__
            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:
                #Empty series so no need to loop
                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]