To update a range of cells, you use the following command.
## Select a range
cell_list = worksheet.range('A1:A7')
for cell in cell_list:
cell.value = 'O_o'
## Update in batch
worksheet.update_cells(cell_list)
For my application, I would like it to update an entire range, but I am trying to set a different value for each individual cell. The problem with this example is that every cell ends up with the same value. Updating each cell individually is inefficient and takes way too long. How can I do this efficiently?
You can use enumerate on a separate list containing the different values you want in the cells and use the index part of the tuple to match to the appropriate cells in cell_list.
Here's my solution if you want to export a pandas data frame to a google sheet with gspread:
We can use this function to update the correct element in the list, cell_list, with the respective value in the dataframe, df.
We can output the results of the list, cell_list, to our worksheet.
Assuming a table with a header row, as follows:
Then, the following should be self explanatory
You could refer these link for more details.