小编Dar*_*eva的帖子

如何使用 python 的 gspread wks.update_cells 更新谷歌电子表格中的单元格

我在 GS 中有一个文档,其中自动上传了带有字符串格式数值的数据。\n在所有单元格中都有一个标记,因此我可以通过删除它来将字符串转换为数字。

\n\n

在此输入图像描述

\n\n

当我使用 gspread 方法更新一个单元格时,它成功运行: wks.update_acell("B7", str(1939.0).replace("\'"," "))

\n\n

但我想用 wks.update_cells 更改范围内的所有单元格。

\n\n

在官方 gspread 文档中有一个例子:

\n\n
cell_list = wks.range(\'A1:C7\')\n\nfor cell in cell_list:\n    cell.value = \'O_o\'\n\n# Update in batch\nwks.update_cells(cell_list)\n
Run Code Online (Sandbox Code Playgroud)\n\n

在这种形式下它可以工作,但在我的情况下 cell.value = str.replace("\'","") 我收到错误:

\n\n
TypeError: replace() takes at least 2 arguments (1 given)\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想我需要将 smth 放在括号 str().replace \xe2\x80\x93 但不明白什么 \xe2\x80\xa6 谁能帮我吗?

\n\n

PS\n完整代码:

\n\n
import pandas as pd\nimport numpy as np\nfrom pandas import Series,DataFrame\nfrom file4dir1 import rep\n\n\n    pd.set_option(\'display.max_columns\',None)\n    pd.set_option(\'display.expand_frame_repr\',False)\n    pd.set_option(\'max_colwidth\',-1)\n\n    mytoken=\'***\'\n    project = \'***\'\n\n …
Run Code Online (Sandbox Code Playgroud)

python-3.x gspread google-sheets-api

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-sheets-api ×1

gspread ×1

python-3.x ×1