Search code examples
pythonpandasgoogle-sheetsgoogle-sheets-apigspread

Add data after the last filled line of Google Sheets, with gspread python


I need to add a dataframe's values to the end of the last row of records in my Google spreadsheet, but I can't. Each time I use the code below, it subscribes to the above information. I'm using a gspread library to update the data in the Google Sheets spreadsheet.

sheet.update([df_data.columns.values.tolist()] + df_data.values.tolist())

I want to add new data after the last filled line. I want to add new data after the last filled line.


Solution

  • In your situation, how about using the method of appendRows?

    Modified script:

    From:

    sheet.update([df_data.columns.values.tolist()] + df_data.values.tolist())
    

    To:

    If you want to append the value of [df_data.columns.values.tolist()] + df_data.values.tolist(), how about the following modification?

    sheet.append_rows([df_data.columns.values.tolist()] + df_data.values.tolist(), value_input_option="USER_ENTERED")
    

    If you want to append the value of df_data.values.tolist(), how about the following modification?

    sheet.append_rows(df_data.values.tolist(), value_input_option="USER_ENTERED")
    

    References: