I want to save pandas data frame directly to Google Cloud Storage. I tried different ways using write-a-pandas-dataframe-to-google-cloud-storage-or-bigquery. But I am not able to save.
Note: I can use google.cloud package only
Below is the code I tried
from google.cloud import storage
import pandas as pd
input_dict = [{'Name': 'A', 'Id': 100}, {'Name': 'B', 'Id': 110}, {'Name': 'C', 'Id': 120}]
df = pd.DataFrame(input_dict)
Try:1
destination = f'gs://bucket_name/test.csv'
df.to_csv(destination)
Try:2
storage_client = storage.Client(project='project')
bucket = storage_client.get_bucket('bucket_name')
gs_file = bucket.blob('test.csv')
df.to_csv(gs_file)
I am getting below errors
for option 1 : No such file or directory: 'gs://bucket_name/test.csv'
option 2: 'Blob' object has no attribute 'close'
Thanks,
Raghunath.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…