def anonymize(self, df, k, l=0): # Check inputs if df is None or len(df) == 0: raise Exception("Dataframe is empty") if self.sensitive_attribute_columns is None or len(self.sensitive_attribute_columns) == 0: raise Exception("Provide at least one sensitive attribute column") if not self.feature_columns: self.init_feature_colums(df) if self.avg_columns: for c in self.avg_columns: if not is_numeric_dtype(df[c]): raise Exception("Column " + c + " is not numeric and average cannot be calculated.") mondrian = MondrianAnonymizer(df, self.feature_columns, self.sensitive_attribute_columns) partitions = mondrian.partition(k, l) dfa = self.build_anonymized_dataframe(df, partitions) return dfa