使用Gspread逐行更新Google Spreadsheet

问题描述 投票:0回答:1

我正在使用Python和gspread将数据插入/更新我的Google电子表格。

我尝试了两种不同的脚本。第一个给我的错误是该对象不可JSON序列化。第二个有效,但由于我达到了API调用的配额而最终停止了。我有很多数据需要更新。

代码1

    row=list(df.iloc[i])
    sheet.insert_row(row, i+2)

代码2

    row=list(df1.iloc[i])
    for j in range(len(row)):
        x = str(row[j])
        sheet.update_cell(i+2,j+1,x)

错误1

TypeError: Object of type Series is not JSON serializable

任何帮助将不胜感激。

json api gspread
1个回答
0
投票

如果在这种情况下i是行号。

     n_rows, n_cols = df.shape
     for i in range(n_rows):
         row_values = list(df.iloc[i])

         # if you want to insert the value of the row at the index i
         sheet.insert_row(row_values,i)
© www.soinside.com 2019 - 2024. All rights reserved.