![](/img/trans.png)
[英]Copy a file from a docker image running on a Google Compute Engine VM to a Google Storage bucket
[英]Saving pandas dataframe variable to csv from google compute engine to google storage bucket without saving to disk first
我有一个名为google-storage-bucket-1
的谷歌云存储桶。
我连接了我的计算引擎实例,并且我有一个 pandas dataframe 变量,它是在 python 中创建的一个名为 df1 的临时变量。
我想将 dataframe 作为 csv 文件保存到存储桶中。 我使用以下命令。
import pandas as pd
df1.to_csv('gs://google-storge-bucket-1/test/dataframe1.csv')
但我收到以下错误,
OSError: Forbidden: https://www.googleapis.com/upload/storage/v1/b/xxx/o
Insufficient Permission
将文件保存到存储桶而不先将其保存到磁盘的正确命令是什么?
像这样:
from google.cloud import storage
import os
from io import StringIO
f = StringIO() ## this is to avoid creating local file
df1.to_csv(f)
f.seek(0)
gcs = storage.Client()
gcs.get_bucket('google-storge-bucket-1').blob('dataframe1.csv').upload_from_file(f, content_type='text/csv')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.