且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Python Flask上传CSV文件并进行处理

更新时间:2023-02-26 18:26:57

(由于它是一个文件,因此名称不太恰当)files变量包含熊猫文档.

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)