-1

I have a .csv file in my localdisk. I want to read this file when I run my flask application. These are the codes which I tried to read the file.

@app.route('/file', methods=['GET'])
def upload():
    file = pd.read_csv(request.files.get('E:\code\flask\winequality-red.csv'))
    print(file)
    return jsonify(file)
davidism
  • 110,080
  • 24
  • 357
  • 317

1 Answers1

0
from flask import Flask,jsonify
import pandas as pd
app = Flask(__name__)

@app.route('/hello')
def helloIndex():
    df = pd.read_csv('./hubble_data.csv')
    return jsonify(df.to_dict(orient='records'))

app.run(host='0.0.0.0', port= 81)

hubble_data.csv:

k,t
1,2
3,4
5,6

Output:

[{"k":1,"t":2},{"k":3,"t":4},{"k":5,"t":6}]

Yang Yu
  • 3,864
  • 6
  • 19
  • 40