'How to remain the first column value as shown in the dataset that used to predict in flask python

I m currently working on my own project which use LSTM model to predict the time series data. I am able to predict the result and attach the predicted value to csv file but unfotunely i have lost my first column name and value, For example, the first column in the csv file I uploaded for prediction is the datetime, how to remain again the first column datatime after i have made prediction and download as a new csv file, Please share me some tips, its really stuck me for a while, So i would like to have some tips regarding this issues, Please give me some advice thanks and appreciate!

from flask import Flask, make_response, request, render_template
import io
from io import StringIO
import csv
import pandas as pd
import numpy as np
import pickle
import os
from keras.models import load_model
from sklearn.preprocessing import MinMaxScaler
from statsmodels.tsa.arima_model import ARIMAResults


app = Flask(__name__)





@app.route('/')
def form():
    return """
        <html>
            <body>
                <h1>Let's TRY to Predict..</h1>
                </br>
                </br>
                <p> Insert your CSV file and then download the Result
                <form action="/transform" method="post" enctype="multipart/form-data">
                    <input type="file" name="data_file" class="btn btn-block"/>
                    </br>
                    </br>
                    <button type="submit" class="btn btn-primary btn-block btn-large">Predict</button>
                </form>
            </body>
        </html>
    """
@app.route('/transform', methods=["POST"])
def transform_view():
 if request.method == 'POST':
    f = request.files['data_file']
    if not f:
        return "No file"

    
    stream = io.StringIO(f.stream.read().decode("UTF8"), newline=None)
    csv_input = csv.reader(stream)
    #print("file contents: ", file_contents)
    #print(type(file_contents))
    print(csv_input)
    for row in csv_input:
        print(row)

    stream.seek(0)
    result = stream.read()
    df = pd.read_csv(StringIO(result), usecols=[1])

    # load the model from disk
    model = load_model('model.h5')
    dataset = df.values
    dataset = dataset.astype('float32')
    scaler = MinMaxScaler(feature_range=(0, 1))
    dataset = scaler.fit_transform(dataset)

    dataset = np.reshape(dataset, (dataset.shape[0], 1, dataset.shape[1]))
    df = model.predict(dataset)
    transform = scaler.inverse_transform(df)    
    df_predict = pd.DataFrame(transform, columns=["predicted value"])
 
            

    response = make_response(df_predict.to_csv(index=True , encoding='utf8'))
    response.headers["Content-Disposition"] = "attachment; filename=result.csv"
    return response



if __name__ == "__main__":
    app.run(debug=True, port = 9000, host = "localhost")

The first column was shown as 'Month' in sequence in the csv file I used to predict, and this is the result after predicted and download as a new csv file

The original column was belong to 'Month'



Solution 1:[1]

Make a copy of the csv file from upload by .copy() and from that copied csv just folter the required folder and concate with your prediction csv..simple.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sabarinath K