I am trying to understand how to write a multiple line csv file to google cloud storage. I'm just not following the documentation
Close to here: Unable to read csv file uploaded on google cloud storage bucket
Example:
from google.cloud import storage
from oauth2client.client import GoogleCredentials
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "<pathtomycredentials>"
a=[1,2,3]
b=['a','b','c']
storage_client = storage.Client()
bucket = storage_client.get_bucket("<mybucketname>")
blob=bucket.blob("Hummingbirds/trainingdata.csv")
for eachrow in range(3):
blob.upload_from_string(str(a[eachrow]) + "," + str(b[eachrow]))
That gets you a single line on google cloud storage
3,c
clearly it opened a new file each time and wrote the line.
Okay, how about adding a new line delim?
for eachrow in range(3):
blob.upload_from_string(str(a[eachrow]) + "," + str(b[eachrow]) + "\n")
that adds the line break, but again writes from the beginning.
Can someone illustrate what the approach is? I could combine all my lines into one string, or write a temp file, but that seems very ugly.
Perhaps with open as file?