以前处理过.csv文件,可以直接上传到GCS。
对于csv,我将执行以下操作,这是可行的:
blob = bucket.blob(path)
blob.upload_from_string(dataframe.to_csv(), 'text/csv')我正在尝试执行相同的操作,即将数据帧作为.feather文件写入存储桶中
blob = bucket.blob(path)
blob.upload_from_string(dataframe.reset_index().to_feather(), 'text/feather')但是,这失败了,因为to_feather()需要一个fname。任何关于我哪里出错的建议/指导都会很有帮助。
发布于 2021-11-24 10:00:42
upload_from_string适用于to_csv()方法,因为‘path’参数是可选的。如果未提供路径,则以字符串形式返回结果。另一方面,to_feather()方法需要指定路径。因此,您应该存储羽化文件,然后将羽化文件上传到GCS。请参考以下代码:
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)https://stackoverflow.com/questions/70075981
复制相似问题