Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. In this task, you will write two new classes, namely series and Dataframe. The

ID: 3733882 • Letter: #

Question

.

In this task, you will write two new classes, namely series and Dataframe. The series class will be used to define either a row or column of data. The Dataframe class will keep a sequence of series objects. Series self, data, name") should initialize the series with the provided sequence of data, where name is the name of this series. You can think of the name as the name of a row of data or a column of data. Pictorially Series( [i, 2, 3, 4, 5], "Rank") can be represented as Rank A Series should support all four arithmetic operations using , -* and /. That is, you must support.add sub mul. and__div. So you should be able to perform these operations on any two Series objects. Datafrane( self, data) will initialize a dataframe from data, a list of lists, where each sublist represents a row of the input data. Datafrane.col[nane] should return the column named by name represented as a Series object. Note that the name of the Series object must match the name passed into..]. Note that you must support.getitem0 to be able to use the notation Datafrane.col[nane] should return the column named by name represented as a Series object. Note that the name of the Series object must match the name passed into..1. Note that you must support_.getiten.) to be able to use the ..1 notation. Datafrane.row[index] should return the row indexed by name as a series object.

Explanation / Answer

Code:

class Series:

        def __init__(self, data, name=''):

                self._data = data

                self._name = name

        def getData(self):

                return self._data

        def getName(self):

                return self._name

        def __add__(self, other):

                self._data.extend(other.getData())

        def __sub__(self, other):

                for x in other.getData():

                        if x in self._data:

                                self._data.remove(x)

        def __mul__(self, other):

                d = self.getData()

                self._data = []

                for x in other.getData():

                        for y in d:

                               self._data.append((x, y))

        # i do not understand what div method should be doing

        # but similarly you can implement that also.

class Dataframe:

        def __init__(self, data):

                self._data = data

        def __getitem__(self, val):

                for l in self._data:

                        if val in l:

                                return Series(l, val)

                return None