Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
 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)
Пример #6
0
 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)
Пример #7
0
    def mongodbHandler(self, request):
        df = dataframeHandler.getDataframe()
        connectionString = request.form.get('connectionString')
        database_name = request.form.get('database')
        collection_name = request.form.get('collection')

        client = pymongo.MongoClient(connectionString)
        database = client[database_name]
        collection = database[collection_name]
        collection.insert_many(df.to_dict('records'))
Пример #8
0
    def csvHandler(self, request):
        df = dataframeHandler.getDataframe()

        filename = request.form.get('filename')
        filebuffer = StringIO()
        df.to_csv(filebuffer)
        filemem = BytesIO()
        filemem.write(filebuffer.getvalue().encode())
        filemem.seek(0)
        filebuffer.close()
        self.filedata['file'] = filemem
        self.filedata['mimetype'] = 'text/csv'
        self.filedata['filename'] = filename
Пример #9
0
    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)
Пример #10
0
 def setTypeFloatHandler(self, request):
     column = request.form.get('column')
     df = dataframeHandler.getDataframe()
     df[column] = pd.to_numeric(df[column], errors='coerce')
     dataframeHandler.saveDataframe(df)
Пример #11
0
 def deleteColumnHandler(self, request):
     column = request.form.get('column')
     df = dataframeHandler.getDataframe()
     df.drop(column, axis=1, inplace=True)
     dataframeHandler.saveDataframe(df)
Пример #12
0
 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)