问题
The project lib documentation shows how to save a pandas dataframe to the project assets:
# 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
However, if I have a local file ...
! wget url_to_binary_file
How can I then upload that file to the project’s assets?
回答1:
I needed to read the file as bytes. Note that this will read the file into memory, don’t try this is you have a file that is larger than your available memory:
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
)
来源:https://stackoverflow.com/questions/51666863/how-can-i-save-a-binary-file-to-my-project-assets-using-project-lib-python