What I’m trying to do:
Hi everyone. I am trying to update (append to) a data file that i have uploaded using the server module. I am unsure exactly what the correct procedure is for editing and overwriting the existing file or if its even possible. My main question here is: what would be the best way to do this and how?
What I’ve tried and what’s not working:
My process is currently as follows:
- User uploads a file that the server reads and edits after converting to a pandas data frame.
- The server takes the edited file and appends the data to the end of the existing data file (located on the datafiles) converted into a pandas dataframe.
- Next i want to overwrite or update the old data file using the newly created pandas dataframe.
The last point is where i get stuck. Should i be following a different process to achieve this or is there a way to code this in the anvil server module?
Thanks in advance!
Code Sample:
df = process_data(f) # User defined function - returns cleaned pandas data frame
df_legacy = pd.read_csv(data_files['old_data.csv'], index_col=0)
df_legacy = df_legacy[df.columns]
# Concat new processed data with the legacy data
df_new = pd.concat([df_legacy, df])
data_files['old_data.csv'] = df_new.to_csv() # Trying to overwrite file - Unsure of correct code or process
**Clone link:**
*share a copy of your app*