python gspread-要求在范围内写作,但尝试写入其他行

发布于 2025-02-13 07:38:32 字数 836 浏览 0 评论 0原文

遇到此代码的问题,该代码将数组转换为DF,然后更新了一个Google表,其中有更多的数据在一周前起作用:

df2 = pd.DataFrame(data, columns=['Col1', 'Col2', 'Col3', 'Col4', 
'Col5', 'Col6', 'Col7', 'Col8'])

gc = gs.service_account(filename=CloudPathCredentials)
ws = gc.open("Spreadsheetname").worksheet("Sheet1")
firsthold = holder[0]
lasthold = holder[-1]
cellmatch1 = ws.find(firsthold)
cellmatch2 = ws.find(lasthold)
begrow = str(cellmatch1.row)
endrow = str(cellmatch2.row)
begrange = "A" + begrow
endrange = "H" + endrow
fullrange = begrange + ":" + endrange
values = df2.values.tolist()
ws.update(fullrange, values)

现在,由于某种原因,数据结束后,它正在尝试写入1行,并引发错误:

gspread.exceptions.APIError: {'code': 400, 'message': 'Requested writing within range [Sheet1!1757:1890], but tried writing to row [1891]', 'status': 'INVALID_ARGUMENT'}

Running into an issue with this code which converted an array into a df then updated a google sheet with more recent data that worked about a week ago:

df2 = pd.DataFrame(data, columns=['Col1', 'Col2', 'Col3', 'Col4', 
'Col5', 'Col6', 'Col7', 'Col8'])

gc = gs.service_account(filename=CloudPathCredentials)
ws = gc.open("Spreadsheetname").worksheet("Sheet1")
firsthold = holder[0]
lasthold = holder[-1]
cellmatch1 = ws.find(firsthold)
cellmatch2 = ws.find(lasthold)
begrow = str(cellmatch1.row)
endrow = str(cellmatch2.row)
begrange = "A" + begrow
endrange = "H" + endrow
fullrange = begrange + ":" + endrange
values = df2.values.tolist()
ws.update(fullrange, values)

now it is attempting to write to 1 row after the data ends for some reason and throws the error:

gspread.exceptions.APIError: {'code': 400, 'message': 'Requested writing within range [Sheet1!1757:1890], but tried writing to row [1891]', 'status': 'INVALID_ARGUMENT'}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文