Upload CSV File Using Python Flask And Process It
I have the following code to upload an CSV file using Python FLASK. from flask_restful import Resource import pandas as pd ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
Solution 1:
The (not so aptly named, due to it being one file) files
variable contains a werkzeug.datastructures.FileStorage object. This is a file like object (containing a read()
method), and as such it is possible to use it directly as input to pandas.read_csv()
as seen in the pandas documentation.
Thus, the solution to not save to disk is as simple as:
class UploadCSV(Resource):
def post(self):
file = request.files['file']
data = pd.read_csv(file)
print(data)
Post a Comment for "Upload CSV File Using Python Flask And Process It"