如何将从Python拉到Google电子表格的表格的文本格式更改为数字格式?

如何将从Python拉到Google电子表格的表格的文本格式更改为数字格式?,python,gspread,Python,Gspread,我有下一个问题。我在Python中有一个数据框,我把它放在谷歌电子表格中,我得到了数字列: 我想要数字格式的数字列。我一直在尝试,但什么都没发生: from gspread_formatting import * fmt = cellFormat(numberFormat=numberFormat(type='NUMBER', pattern='####.#')) format_cell_range(worksheet, 'Q2:R2', fmt) 如果我在fmt中放入一个随机文本格式(如

我有下一个问题。我在Python中有一个数据框,我把它放在谷歌电子表格中,我得到了数字列:

我想要数字格式的数字列。我一直在尝试,但什么都没发生:

from gspread_formatting import *

fmt = cellFormat(numberFormat=numberFormat(type='NUMBER', pattern='####.#'))
format_cell_range(worksheet, 'Q2:R2', fmt)
如果我在fmt中放入一个随机文本格式(如背景色),它会工作…所以,我不知道为什么转换为numberFormat不工作

在Python数据框中,这些列采用数字格式:

谢谢

编辑 这是将数据帧从Python放到Google工作表的代码:

import df2gspread as d2g
    def spreadsheet_first_paste(file_name, sheet_id,sheet_name, df):
        scope = ['https://spreadsheets.google.com/feeds',
                 'https://www.googleapis.com/auth/drive']
        creds = ServiceAccountCredentials.from_json_keyfile_name('...path/client_secret.json',scope)
        
        gc = gspread.service_account(filename='...path/client_secret.json')               
        sh = gc.open(file_name)
        spreadsheet_key = sheet_id
        wks_name = sheet_name
        d2g.upload(df, spreadsheet_key, wks_name, credentials=creds, row_names=True)
EDIT2 解决了的:
在那篇文章中有一个解决方案:我使用的是df2gspread库,所以我转到了df2gspread.py,并将行“wks.update_cells(cell_list)”修改为“wks.update_cells(cell_list,value_-input_-option='USER_-ENTERED')”

在您的情况下,我可以问一下从dataframe输入值的脚本吗?因为当将值放入电子表格时,当使用
value\u input\u option='USER\u ENTERED'
时,数字会作为数字。但是在gspread中,
value\u input\u选项的默认值是
RAW
。我想这样,你的问题可能会出现。这个怎么样?嗨,塔奈克,我用剧本编辑了这篇文章!谢谢你的回复。我很高兴你的问题解决了。