'How can I change the text format to number format of a table pulled from Python to a Google spreadsheet?

I got the next problem. I have a dataframe in Python and I putted it in a Google Spreadsheet and I got this for the numeric columns:

enter image description here

I want the numeric columns in a numeric format. I've been trying this but nothing happens:

from gspread_formatting import *

fmt = cellFormat(numberFormat=numberFormat(type='NUMBER', pattern='####.#'))
format_cell_range(worksheet, 'Q2:R2', fmt)

If I put a random text format inside fmt (like background color), it works...So, I don´t know why the transform to numberFormat isn´t working...

In the Python dataframe, these columns are in a numeric format:

enter image description here

Thanks!

EDIT This is the code of put the dataframe from Python to a Google sheet:

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 SOLVED: Problem with data format while Importing pandas DF from python into google sheets using df2gsheets In that post was the solution: I was using the df2gspread library, so I went to the df2gspread.py and modified the lines "wks.update_cells(cell_list)" to "wks.update_cells(cell_list, value_input_option='USER_ENTERED')"



Solution 1:[1]

This solution really worked. Thanks for posting the solution: SOLVED: I was using the df2gspread library, so I went to the df2gspread.py and modified the lines "wks.update_cells(cell_list)" to "wks.update_cells(cell_list, value_input_option='USER_ENTERED')"

python gspread

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thiyagaraaj Shanmugam