Rumah  >  Soal Jawab  >  teks badan

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

怪我咯怪我咯2742 hari yang lalu971

membalas semua(2)saya akan balas

  • 怪我咯

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

    Saya rasa stringIO boleh menyelesaikan masalah anda. Gunakannya untuk menyimpan kandungan file.stream dahulu. Lulus ke pd.

    balas
    0
  • PHP中文网

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

    .xls bukan fail teks dan tetapan pengekodan seharusnya tidak sah.
    Tunggu sehingga fail dimuat turun sebelum pd.read_excel()


    read_excel(io)
    io boleh menjadi pencari sumber seperti url atau ftp.
    Jika anda tahu lokasi .xls, anda boleh membukanya terus.

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

    Cubalah, terus pd.read_excel(file) atau (file.stream)

    file = request.files['files']
    taxidata_from_excel = pd.read_excel(file) # (file.stream)

    balas
    0
  • Batalbalas