在使用Python Gspread时,如何删除隐形撇号

发布于 2025-02-04 07:34:31 字数 886 浏览 4 评论 0原文

下面的代码有效。我遇到的问题是一个不可见的'出现在Google表中,然后在第一个列中的所有值'问题'中。

我试图如其他资源中所述更改Google表上的格式,但是将此INT字符串更改为一个数字不起作用。

我相信这个问题是在将价值传递给床单的同时格式化,但是Gspread文档中没有任何解释如何解决此问题的方法。

import gspread
import pandas as pd

data=[['1, 2', 'hello', 4], ['3, 4', 'there', 3]]
cols = ['problem', 'words', 'ints']

df = pd.DataFrame(data=data, columns=cols)
df_as_lists = df.values.tolist()

svc_acct = gspread.service_account_from_dict(info=gs_key)
sheet = svc_acct.open_by_url('https://docs.google.com/spreadsheets/d/1cW1ry2FwlEOGSF270skXLN52UeqWkhgFXfeDVqH_a3M/edit#gid=0')
wks = sheet.worksheet('Sheet1')
wks.update('A1:C3', df_as_lists)

床单中的当前值:

  lists  words  ints
0  '1, 2  hello     4
1  '3, 4  there     3

床单中所需的值:

  lists  words  ints
0  1, 2  hello     4
1  3, 4  there     3

The code below works. The problem I am encountering is an invisible ' appears in the google sheet before all values in the first column 'problem'.

I have attempted to change the formatting on the google sheet as described in other resources, but changing this string of ints to a number doesn't work.

I believe the issue is formatting while passing the values to Sheets, but there is nothing in the gspread docs that explain how to fix this.

import gspread
import pandas as pd

data=[['1, 2', 'hello', 4], ['3, 4', 'there', 3]]
cols = ['problem', 'words', 'ints']

df = pd.DataFrame(data=data, columns=cols)
df_as_lists = df.values.tolist()

svc_acct = gspread.service_account_from_dict(info=gs_key)
sheet = svc_acct.open_by_url('https://docs.google.com/spreadsheets/d/1cW1ry2FwlEOGSF270skXLN52UeqWkhgFXfeDVqH_a3M/edit#gid=0')
wks = sheet.worksheet('Sheet1')
wks.update('A1:C3', df_as_lists)

Current values in Sheets:

  lists  words  ints
0  '1, 2  hello     4
1  '3, 4  there     3

Desired values in Sheets:

  lists  words  ints
0  1, 2  hello     4
1  3, 4  there     3

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

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

发布评论

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