Last Updated on March 27, 2023 by mishou

Let’s create a simple but practical data set and deal with it using data frames, dictionaries and objects. We will learn how differently they handle the data.

I. Using Data Frames


II. Using Dictionaries

III. Using Objects

# Using .rank() with Subclass
class Comparison():

    def __init__(self, id, group, english, math): = id = group
        self.english = english
        self.math = math
        self.rank = 0 = self.english + self.math
        self.average = (self.english + self.math)/2

    def all(self):
        print(f"Your average is {self.average}.")
class Comparisons(dict):

    def __init__(self):
        super(Comparisons, self).__init__()

    def rank(self):
        sorted_comparisons = sorted(self.values(), key=lambda c: c.average, reverse=True)
        for rank, comparison in enumerate(sorted_comparisons, 1):
            comparison.rank = rank
comparison instances
print the attributes

We will create Subclasses to use .rank( ). See more information here:

What is the best approach to rank a dictionary of objects?

IV. The Scripts

You can see the scripts here though they are not completed.

By mishou

Leave a Reply

Your email address will not be published. Required fields are marked *