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

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

全部回复(2)
怪我咯

我觉得 stringIO 可以解决你的问题 。用它来先保存下file.stream 内容。在传给pd。

PHP中文网

.xls不是文本文件, 设置encoding应该是无效的。
老老实实等文件下载完,再 pd.read_excel()


read_excel(io)
io可以是 url、ftp 之类的资源定位符。
如果你知道.xls的位置,可以直接打开。

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

试一下,直接 pd.read_excel(file) 或 (file.stream)

file = request.files['files']
taxidata_from_excel = pd.read_excel(file) # (file.stream)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号