【问题标题】:Read numeric data with the right format from Google Sheets API从 Google Sheets API 读取具有正确格式的数字数据
【发布时间】:2021-08-18 15:33:50
【问题描述】:

我想使用 Python 和 Google API 读取 Google Sheet 中的数字单元格。 在 Google 表格中,对于十进制值,我们使用逗号作为小数分隔符。 我不想更改格式,当我读取数据时,结果只是忽略了逗号。 示例:对于 0,8 的值,我得到 8 作为结果。

这是我的代码:

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

输入:

0,8
6,3

预期输出:

0.8
6.3

当前输出:

8
63

我在 Google 文档中找不到任何内容来格式化读取和读取逗号作为小数分隔符。 各位大神有解决办法吗?

【问题讨论】:

  • 单元格中的数据是存储为浮点数还是格式化整数?
  • @WilliamPearsall 单元格中的数据都存储为一个数字,我想这意味着谷歌表格的浮动。

标签: python api google-sheets


【解决方案1】:

我使用的是 gspread 4.0.1 版。输入是

采用自动格式。

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)

输出是

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多