1

Previously worked on .csv files which was straightforward to upload to GCS

For csv I would do the following, which works:

blob = bucket.blob(path)
blob.upload_from_string(dataframe.to_csv(), 'text/csv')

I am trying to do the same i.e. write the dataframe as a .feather file in bucket

blob = bucket.blob(path)
blob.upload_from_string(dataframe.reset_index().to_feather(), 'text/feather')

However, this fails saying to_feather() requires a fname. Any suggestions/guidance on where I went wrong would be helpful.

Kyo
  • 27
  • 4

1 Answers1

0

upload_from_string works for the to_csv() method because the ‘path’ parameter is optional. When no path is provided, the result is returned as a string. On the other hand, the to_feather() method requires a path specified. So you should store the feather file and then upload the feather file into GCS. Refer the code below:

dataFrame.reset_index().to_feather(FILE PATH)

bucket_name = "BUCKET-NAME"
source_file_name = "FILE PATH"
destination_blob_name = "GCS Object Name"

storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)

blob.upload_from_filename(source_file_name)