-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
  • 121,510
  • 29
  • 395
  • 339

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}]

Wang Liang
  • 4,244
  • 6
  • 22
  • 45