小编Kir*_*wty的帖子

使用Python访问Google Sheets Api

我目前正在尝试通过python更新Google表格,但遇到权限方面的一些问题。

我一直在遵循Twilio指南中的说明:https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet- in-python.html

我正在Jupyter中完成所有这些工作,并且确实将JSON文件保存到了正确的代码目录中。我没有定义范围,信誉和客户的问题。

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_id.json', scope)
client = gspread.authorize(creds)

sheet = client.open("MixIQ Tracker").sheet1
Run Code Online (Sandbox Code Playgroud)

我已经完成了链接两者的所有步骤,但是最后一行却出现了此API错误。

APIError: {
"error": {
  "errors": [{
      "domain": "global",
      "reason": "insufficientPermissions",
      "message": "Insufficient Permission: Request had insufficient authentication scopes."
    }],
  "code": 403,
  "message": "Insufficient Permission: Request had insufficient authentication scopes."
 }
}
Run Code Online (Sandbox Code Playgroud)

我不确定如何解决此问题。任何方向将不胜感激!

python google-sheets-api

8
推荐指数
1
解决办法
1800
查看次数

尝试使用str.contains和boolean mask,但是在Pandas中只有两个单值实例

我想要做的是保持所有行具有相同的唯一IDIF.这些行中的任何一行在Yurt列中仅包含两个" - "实例.

我正在考虑str.contains通过执行以下操作来使用a 和布尔掩码:

df[df['ID'].isin(df.loc[df.Yurt.str.contains('-'), 'ID'].unique())]
Run Code Online (Sandbox Code Playgroud)

...但不确定我如何只保留只有两个没有值的实例的行.

示例df:

ID      %       Yurt
abc123  0.833   Bodega
abc123  0.87    -
abc123  0.867   -
abc123  0.812   -
lmn789  0.837   Mickey's
lmn789  0.856   Chopped Cheese
lmn789  0.813   -
lmn789  0.812   -
xyz456  0.111   -
xyz456  0.222   -
xyz456  0.333   -
xyz456  0.444   -
Run Code Online (Sandbox Code Playgroud)

结果df:

ID      %       Yurt
lmn789  0.837   Mickey's
lmn789  0.856   Chopped Cheese
lmn789  0.813   -
lmn789  0.812   -
Run Code Online (Sandbox Code Playgroud)

python string boolean pandas pandas-groupby

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