Dynamic feature selection using Python Flask

<input type="checkbox" id="meanT" name="tdf" value="meanT">
  <label for="mean"> Mean</label><br>
  <input type="checkbox" id="stdT" name="tdf" value="stdT">
  <label for="std"> Standard Deviation</label><br>
  <input type="checkbox" id="medianT" name="tdf" value="medianT">
  <label for="median"> Median</label><br>
  
  <input type="checkbox" id="madT" name="tdf" value="madT">
  <label for="mad"> Mean Absolute Deviation </label><br>
  <input type="checkbox" id="rmsT" name="tdf" value="rmsT">
  <label for="rms"> Root Mean Square</label><br>
  <input type="checkbox" id="covT" name="tdf" value="covT">
  <label for="cov"> Covariance</label><br>

app.py

import os`
    `ROOT_PATH = os.path.dirname(os.path.abspath(__file__))`
    
    `files = request.files['fs_file']`
    
    `files.save(os.path.join(ROOT_PATH,files.filename))
     import pandas
     raw_csv2 = pandas.read_csv(os.path.join(ROOT_PATH,files.filename))
     X=raw_csv2.iloc[:,:-1]
     print(X)
     print(len(X.columns))
     np.savetxt("D:/tool/feat_tobe_sel.csv",X,delimiter=',',fmt='%s')
     from scipy.fftpack import fft
     final=[]`
    

    `final_mean = np.empty((1,len(X.columns)),np.float64)
     final_std = np.empty((1,len(X.columns)),np.float64)
     final_median = np.empty((1,len(X.columns)),np.float64)

     final_mad = np.empty((1,len(X.columns)),np.float64)
     final_rms = np.empty((1,len(X.columns)),np.float64)
     final_cov = np.empty((1,len(X.columns)),np.float64)`
            
     `for feature in features:
        print(feature)
        if feature=='meanT':
            for chunk in pd.read_csv('D:/tool/feat_tobe_sel.csv',chunksize=250):
                mean = np.array(chunk.mean())#mean
                final_mean=np.append(final_mean,[mean],axis=0)
                print("meanT")                             
                
            
        elif feature=='stdT':
            for chunk in pd.read_csv('D:/tool/feat_tobe_sel.csv',chunksize=250):
                std = np.array(chunk.std())#standard deviation
                final_std = np.append(final_std, [std], axis=0)
                print("stdT")
                
        
        
                                
        elif feature=='medianT':
            for chunk in pd.read_csv('D:/tool/feat_tobe_sel.csv',chunksize=250):
                median = np.array(chunk.median())#median
                final_median = np.append(final_median, [median], axis=0)
                print("medianT")
                
        elif feature=='madT':
            for chunk in pd.read_csv('D:/tool/feat_tobe_sel.csv',chunksize=250):
                mad = np.array(chunk.mad())
                final_mad = np.append(final_mad, [mad], axis=0)
                
                
        elif feature=='rmsT':
            for chunk in pd.read_csv('D:/tool/feat_tobe_sel.csv',chunksize=250):
                rms = np.array(np.sqrt(np.mean(chunk**2)))
                final_rms = np.append(final_rms, [rms], axis=0)
                print("rmsT")
              
        elif feature=='covT':
            for chunk in pd.read_csv('D:/tool/feat_tobe_sel.csv',chunksize=250):
                cov = chunk.cov()
                for covItem in cov:
                    final_cov = np.append(final_cov, [np.array(cov[covItem])], axis=0)`
`

           `df2=pandas.DataFrame(final_mean)
            df3=pandas.DataFrame(final_std)
            df4=pandas.DataFrame(final_median)
            df5=pandas.DataFrame(final_mad)
            df6=pandas.DataFrame(final_rms)
            df7=pandas.DataFrame(final_cov)
            dfs = [df2,df3,df4,df5,df6,df7]`
                
        `non_empty=[df for df in dfs if len(df)!=0]
        
        dfm=pd.concat(non_empty,axis=1)
        
        np.savetxt(r"D:/tool/features_selected.csv",dfm,delimiter=',',fmt='%s') `
     `return rendertemplates("feat.html")` 

What is your question?

I wanted to select the features dynamically through the front end developed in html… and only the selected features has to be extracted and concatenated along column and the same has to be written in .csv file.

The code and information you provided is unfortunately not sufficient to really provide help. It’s not a minimal example I could run; I don’t know where exactly your difficulties arise and what you’ve tried so far; and it’s not even a Flask App at this stage…

Respected Sir,
Thank you for your response sir!!!
Apologies for providing less data…
Herewith I attached a part of the code for your reference.
Here, an optimization algorithm (de.py) is applied to select the features from the final_feature.csv file, those selected features alone are extracted from S1_T1_labeled.csv file and the extracted features have to be saved in .csv format along the column.
I would be grateful if you help me to fix this issue.
Thanks in advance.

(Attachment app_test.py is missing)

(Attachment final_feature.csv is missing)

(Attachment de.py is missing)

(Attachment S1_T1_labeled.csv is missing)

Respected Sir,
Thank you for your response sir!!!
Apologies for providing less data…
Herewith I attached a part of the code for your reference.
Here, an optimization algorithm (de.py) is applied to select the features from the final_feature.csv file, those selected features alone are extracted from S1_T1_labeled.csv file and the extracted features have to be saved in .csv format along the column.
I would be grateful if you help me to fix this issue.
Thanks in advance.

app.py

@app.route(‘/feature_selection’, methods =[‘GET’, ‘POST’])
def feature_selection():
if request.method == ‘POST’:
features=request.form.getlist(‘tdf’)

import os`
import numpy as np
import pandas

from scipy import signal