I am trying to use Google Cloud Function to query from bigquery and save a dataframe into a file. I've tried the code with the Jupyter that comes with GCP and it's a success. However, when I copy the code to Cloud Function and test it. I got an error message as following:
OSError: [Errno 30] Read-only file system: 'dataframe.csv'
My code can be found below:
def save_dataframe(dataframe, filename):
client = storage.Client(project="my-first-project")
bucket = client.get_bucket("test_bucket")
dataframe.to_csv(filename)
blob = bucket.blob(filename)
blob.upload_from_filename(filename)
save_dataframe(dataframe, "dataframe.csv")
I have another function which works fine:
def save_model(models, filename):
client = storage.Client(project="my-first-project")
bucket = client.get_bucket("test_bucket")
blob = bucket.blob(filename)
pickle_out = pickle.dumps(models)
blob.upload_from_string(pickle_out)