首頁  >  問答  >  主體

python - POST上传的excel(xls)文件,如何直接读进pandas,避免写入到磁盘?

怪我咯怪我咯2742 天前982

全部回覆(2)我來回復

  • 怪我咯

    怪我咯2017-04-18 09:40:44

    我覺得 stringIO 可以解決你的問題 。用它來先儲存下file.stream 內容。在傳給pd。

    回覆
    0
  • PHP中文网

    PHP中文网2017-04-18 09:40:44

    .xls不是文字文件, 設定encoding應該是無效的。
    老實等文件下載完,再 pd.read_excel()


    read_excel(io) io)
    io可以是 url、ftp 之类的资源定位符。
    如果你知道.xlsio可以是 url、ftp 之類的資源定位符。

    如果你知道
    的位置,可以直接打開。

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

    回覆
    0
  • 取消回覆