在使用Python Gspread时,如何删除隐形撇号
下面的代码有效。我遇到的问题是一个不可见的'
出现在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论