Esempio n. 1
0
 def applyMaskString(self, maskString, bAdd=True):
     df = self.data
     Index = np.array(range(df.shape[0]))
     sMask = maskString.replace('{Index}', 'Index')
     for i, c in enumerate(self.columns):
         c_no_unit = no_unit(c).strip()
         c_in_df = df.columns[i]
         # TODO sort out the mess with asarray (introduced to have and/or
         # as array won't work with date comparison
         # NOTE: using iloc to avoid duplicates column issue
         if isinstance(df.iloc[0, i], pd._libs.tslibs.timestamps.Timestamp):
             sMask = sMask.replace('{' + c_no_unit + '}',
                                   'df[\'' + c_in_df + '\']')
         else:
             sMask = sMask.replace('{' + c_no_unit + '}',
                                   'np.asarray(df[\'' + c_in_df + '\'])')
     df_new = None
     name_new = None
     if len(sMask.strip()) > 0 and sMask.strip().lower() != 'no mask':
         try:
             mask = np.asarray(eval(sMask))
             if bAdd:
                 df_new = df[mask]
                 name_new = self.raw_name + '_masked'
             else:
                 self.mask = mask
                 self.maskString = maskString
         except:
             raise Exception('Error: The mask failed for table: ' +
                             self.name)
     return df_new, name_new
Esempio n. 2
0
 def evalFormula(self,sFormula):
     df = self.data
     Index = np.array(range(df.shape[0]))
     sFormula=sFormula.replace('{Index}','Index')
     for i,c in enumerate(self.columns):
         c_no_unit = no_unit(c).strip()
         c_in_df   = df.columns[i]
         sFormula=sFormula.replace('{'+c_no_unit+'}','df[\''+c_in_df+'\']')
     #print(sFormula)
     try:
         NewCol=eval(sFormula)
         return NewCol
     except:
         return None
Esempio n. 3
0
 def columns_clean(self):
     return [no_unit(s) for s in self.columns]