vendredi 9 février 2018

Normalize two dataframes to one type - class construction -python

I have this design pattern problem, where I get 2 different dataframes and I have to normalize both to a same format so that I can make arithmetic operations on the dataframes.

I am currently on this design, I need advice if there is any better way of executing it.

    class Data1Normalizer:
        def normalize(self):
             return df

    class Data2Normalizer:
        def normalize(self):
             return df

I have a seperate class to make arithmetic operations from the output of 2 classes above

import Data1Normalizer, Data2Normalizer

class Operations:
   def __init__(self, df):
     if df.name == "Data1":
          self.operate = Data1Normalizer().normalize()
     elif df.name == "Data2":
          self.operate = Data2Normalizer().normalize()
     else df.name == "resultdf":
          self.operate = df

    def __add__(self, other):
          #Here custom operations between self and other dataframes
          return Operations(resultdf)

Also how to inherit pandas dataframe functions on Operations(df) ?

I must say, I am just hard typing the code and it may have errors. I am just looking for ideas

Aucun commentaire:

Enregistrer un commentaire