1

项目 lib 文档展示了如何将 pandas 数据框保存到项目资产中:

 # Import the lib
 from project_lib import Project
 project = Project(sc,"<ProjectId>", "<ProjectToken>")

 # let's assume you have the pandas DataFrame  pandas_df which contains the data
 # you want to save in your object storage as a csv file
 project.save_data("file_name.csv", pandas_df.to_csv())

 # the function returns a dict which contains the asset_id, bucket_name and file_name
 # upon successful saving of the data

但是,如果我有一个本地文件...

! wget url_to_binary_file

然后如何将该文件上传到项目的资产中?

4

1 回答 1

2

我需要将文件读取为字节。请注意,这会将文件读入内存,不要尝试这是您的文件大于可用内存:

import io

filename = ‘thefilename’
with open(filename, 'rb') as z:
        data = io.BytesIO(z.read())
        project.save_data(
            filename, data, set_project_asset=True, overwrite=True
        )
于 2018-08-03T06:53:22.790 回答