Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality in df_to_sheet to append data to an existing sheet #86

Open
timdmulligan opened this issue Apr 8, 2022 · 4 comments

Comments

@timdmulligan
Copy link

Hi Diego! Currently in gspread_pandas.spread.Spread().df_to_sheet() you are limited to either wiping the sheet or overwriting existing rows using the replace parameter. How feasible would it be to add an option to append to an existing sheet instead of just overwriting when replace = False? Based on some googling, I think the answer probably lies in values_append within gspread.

If you can get me pointed in the right direction I'll see if I can put together a PR.

@HgCNO2
Copy link

HgCNO2 commented May 4, 2022

For now, you could use a workaround:

spread = Spread('example')
spread.df_to_sheet(df, sheet="sheet", start=(spread.get_sheet_dims("sheet")[0]+1,1), headers=False)

@aiguofer
Copy link
Owner

Hey! sorry the notifications for this must have slipped through my e-mail. The above workaround def should work well when the data starts in A1 and the column order is the same, but it gets complicated when it doesn't.

It seems like an append_to_sheet method would be a good addition, we just need to make sure that we address the following corner cases:

  • does the data fill all available columns/rows or is the worksheet bigger than the data?
  • does the data start at A1 or elsewhere?
  • are the columns and their order still the same or has it changed?

I imagine the goal of append over replace is simply to reduce the number of API calls and amount of data sent over the wire, which might complicate things because we might still need to fetch data to figure out the answers to the above questions...

@mrkobk
Copy link

mrkobk commented Oct 19, 2022

@aiguofer wondering if there is any updated on this? would indeed be ace if the package would be extend with a append_to_sheet for the very reasons you mentioned above. thanks

@jb261
Copy link

jb261 commented Dec 11, 2022

Agreed, append and prepend (for adding rows to table sorted in reverse chronological order) functionality would be very useful.

I imagine the goal of append over replace is simply to reduce the number of API calls and amount of data sent over the wire, which might complicate things because we might still need to fetch data to figure out the answers to the above questions...

Yes, reading data from spreadsheet into dataframe, updating, then dumping enlarged dataframe into worksheet is a clunky solution, and gets worse as the dataset grows in size.

Yes, would probably need to fetch last row of data (for append) or first row of data (for prepend) to figure out where to write, and of course could have optional parameters for user to specify certain characteristics of data to reduce the number of parameters the function needs to determine on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants