python - POST上传的excel(xls)文件,如何直接读进pandas,避免写入到磁盘?
怪我咯
怪我咯 2017-04-18 09:38:44
0
2
976
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
刘奇

I think stringIO can solve your problem. Use it to save the file.stream content first. Passing to pd.

Ty80

.xlsIt is not a text file, and setting the encoding should be invalid.
Hold on and wait until the file is downloaded before pd.read_excel()


read_excel(io) io)
io可以是 url、ftp 之类的资源定位符。
如果你知道.xlsio can be a resource locator such as url or ftp.

If you know the location
, you can open it directly.

>>>help(pd.read_excel)
Help on function read_excel in module pandas.io.excel:

read_excel(io, …………)
    Read an Excel table into a pandas DataFrame
    
    Parameters
    ----------
    io : string, path object (pathlib.Path or py._path.local.LocalPath),
        file-like object, pandas ExcelFile, or xlrd workbook.
        The string could be a URL. Valid URL schemes include http, ftp, s3,
        and file. For file URLs, a host is expected. For instance, a local
        file could be file://localhost/path/to/workbook.xlsx
🎜Try it, directly pd.read_excel(file) or (file.stream)🎜
file = request.files['files']
taxidata_from_excel = pd.read_excel(file) # (file.stream)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!