Nicolas Chea
Nicolas Chea

Reputation: 13

Read numeric data with the right format from Google Sheets API

I want to read numeric cells in a Google Sheet with Python and the Google API. In the Google Sheet, for the decimal values, we use a comma as a decimal separator. I don't want to change the format and when I read the data the result just ignores the comma. Example : For a value of 0,8, I get 8 as a result.

Here's my code :

sheet = google_sheets_connection() # API connection 
sheet = sheet.worksheet(sheet_name)
data = sheet.get_all_records()  
print(data)

Input :

0,8
6,3

Expected output :

0.8
6.3

Current output :

8
63

I don't find anything on the Google documentation to format the reading and read commas as decimal separator. Do you guys have a solution for this ?

Upvotes: 1

Views: 1303

Answers (1)

yoonghm
yoonghm

Reputation: 4625

I am using gspread version 4.0.1. The input is

enter image description here

with Automatic format.

See the documentation for get_all_records()

sheet = google_sheets_connection() # API connection 
sheet = sheet.worksheet(sheet_name)
data = sheet.get_all_records(numericise_ignore=['all'])  
print(data)

The output is

[{'0,8': '6,3'}]

Upvotes: 1

Related Questions