【问题标题】:Sending dataframe as parquet file directly to dropbox将数据帧作为镶木地板文件直接发送到保管箱
【发布时间】:2021-09-16 10:47:10
【问题描述】:

在我的脚本中,我生成了一个数据框,我想将它作为 parquet 文件直接上传到 Dropbox。我设法找到了这样的解决方案:

https://gist.github.com/MaxHalford/f17994c77bb775fdd04c9cd925e0b279

这可以帮助我保存数据框。但是,我真的很想直接发送拼花文件。

对我来说似乎很直观的选项:

fileToSave=tempDf.to_parquet('newFile.parquet')
upload_file(dbx, file_location, fileToSave)

但它会抛出

TypeError: expected str, bytes or os.PathLike object, not NoneType

你知道怎么做吗?

【问题讨论】:

    标签: file-upload dropbox parquet dropbox-api uploading


    【解决方案1】:

    当您调用fileToSave=tempDf.to_parquet('newFile.parquet') 时,它会将表保存在名为newfile.parquet 的本地文件中并返回None

    你想要做的是:

    data = tempDf.to_parquet() #  bytes content of the parquet file
    dbx.files_upload(
            f=data,
            path=path,
            mode=dropbox.files.WriteMode.overwrite
        )
    

    这会将 df 转换为字节(在内存中),然后您可以将其上传到保管箱。

    【讨论】:

      猜你喜欢
      • 2020-06-30
      • 2017-05-06
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 2017-04-25
      • 1970-01-01
      • 2021-03-26
      相关资源
      最近更新 更多