def mostFrecuencyImputingHandler(self, request): print("mostFrecuencyImputingHandler") df = dataframeHandler.getDataframe() column = request.form.get('column') df[[column]] = df[[column]].fillna(df[[column]].mode().iloc[0]) pd.set_option("max_columns", None) # show all cols dataframeHandler.saveDataframe(df)
def kNearestNeighborsImputingHandler(self, request): df = dataframeHandler.getDataframe() column = request.form.get('column') n_neighbors = request.form.get('n_neighbors') encoders = dict() df_copy = df.copy() for col_name in df_copy.columns: print(col_name, df_copy[col_name].dtype) if (df_copy[col_name].dtype == "object"): series = df_copy[col_name] label_encoder = preprocessing.LabelEncoder() df_copy[col_name] = pd.Series( label_encoder.fit_transform(series[series.notnull()]), index=series[series.notnull()].index ) encoders[col_name] = label_encoder else: print("Column", col_name, "not encoded") imputer = KNNImputer(n_neighbors=int(n_neighbors)) imputedData = imputer.fit_transform(df_copy) imputed_dataframe = pd.DataFrame(imputedData, columns=df_copy.columns) if(df[column].dtype == "object"): imputed_dataframe[[column]] = imputed_dataframe[[column]].astype(int) imputed_dataframe[[column]] = encoders[column].inverse_transform(imputed_dataframe[[column]]) df[[column]] = imputed_dataframe[[column]] dataframeHandler.saveDataframe(df)
def averageImputingHandler(self, request): df = dataframeHandler.getDataframe() column = request.form.get('column') axis = request.form.get('axis') print("axis: ", axis) print("column: ", column) df[[column]] = df[[column]].fillna(df.mean(axis=int(axis))) pd.set_option("max_columns", None) # show all cols dataframeHandler.saveDataframe(df)
def setTypeHandler(self, request): _type = request.form.get('type') if _type in self.typesHandlers: self.typesHandlers[_type](request) else: column = request.form.get('column') df = dataframeHandler.getDataframe() df[[column]] = df[[column]].astype(_type) dataframeHandler.saveDataframe(df)
def interpolationImputingHandler(self, request): df = dataframeHandler.getDataframe() column = request.form.get('column') method = request.form.get('method') order = request.form.get('order') axis = request.form.get('axis') # df = df.interpolate(method='polynomial', order=2, axis=0) df[[column]] = df[[column]].interpolate(method=method, order=int(order), axis=int(axis)) pd.set_option("max_columns", None) # show all cols dataframeHandler.saveDataframe(df)
def updateCellHandler(self, request): column = request.form.get('column') row = int(request.form.get('row')) value = request.form.get('value') if not value or value.isspace(): value = None df = dataframeHandler.getDataframe() pd.set_option("max_columns", None) # show all cols df.at[row, column] = value dataframeHandler.saveDataframe(df)
def exampleActionHandler(self, request): df = dataframeHandler.getDataframe() column = request.form.get('column') axis = request.form.get('axis') # ** HERE YOUR CODE FOR EXAMPLE ACTION HANDLER OF THIS PLUGIN ** # modify df and it will be saved with dataframeHandler class in the # local cache and then returned in # Obtain the params from the request exampleSelect = request.form.get('exampleSelect') exampleNumber = request.form.get('exampleNumber') exampleString = request.form.get('exampleString') exampleFile = request.files['exampleFile'] # do something like print params print("exampleSelect: ", exampleSelect) print("exampleNumber: ", exampleNumber) print("exampleString: ", exampleString) print("exampleFile: ", exampleFile) # always save the dataframe in the local cache dataframeHandler.saveDataframe(df)
def setTypeFloatHandler(self, request): column = request.form.get('column') df = dataframeHandler.getDataframe() df[column] = pd.to_numeric(df[column], errors='coerce') dataframeHandler.saveDataframe(df)
def deleteColumnHandler(self, request): column = request.form.get('column') df = dataframeHandler.getDataframe() df.drop(column, axis=1, inplace=True) dataframeHandler.saveDataframe(df)
def deleteRowHandler(self, request): row = int(request.form.get('row')) df = dataframeHandler.getDataframe() df = df.drop(row) df = df.reset_index(drop=True) dataframeHandler.saveDataframe(df)
def csvHandler (self, file: any): df = pd.read_csv(file) dataframeHandler.saveDataframe(df)