Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Appending data to a CSV file within a flask app

Hi! As seen in the title, I can't seem to add/append data or text to the csv that I have uploaded to my flask app that is being deployed in Google Cloud Run. But when I try it locally using Jupyter Notebook, it seems to work just fine. 

Here is the code

#load the csv

features = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
url_data = pd.read_csv("RetrainDatabase.csv",low_memory=False)

#append the new data features
url_data.loc[len(url_data )] = features

#save the new csv
url_data.to_csv("RetrainDatabase_V2.csv", index=False)


0 1 339
1 REPLY 1

Hi Kervin,

  • Is the csv file dynamically uploaded or part of your source code? If you deploy it with your source code, the containing folder may be read-only (TODO: find reference).
  • Can you check the log and share the error message you're getting?
  • Note that the filesystem is fully stateless and in-memory (files are temporary, the next request can be executed in another instance): https://cloud.google.com/run/docs/container-contract#filesystem
  • It's a common practice to work on temporary files under `/tmp`.