Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python将Google表单链接到Google工作表?_Python_Google Sheets_Google Drive Api_Google Forms_Pydrive - Fatal编程技术网

如何使用Python将Google表单链接到Google工作表?

如何使用Python将Google表单链接到Google工作表?,python,google-sheets,google-drive-api,google-forms,pydrive,Python,Google Sheets,Google Drive Api,Google Forms,Pydrive,以下是我的设置和我想要完成的: 我目前有一个谷歌表单,供用户提交信息,然后登录到谷歌表单中 然后,我使用PyDrive将Google工作表的内容保存为csv Pandas然后读取该csv,并根据特定标准删除csv中的数据 在那之后,我使用PyDrive将“固定”csv重新上传到Google工作表,保存旧的csv 问题是: 每当我这样做时,它就会终止Google表单和Google表单之间的链接。有什么方法可以保留此链接或重新链接表单和工作表 下面是我一直在玩的代码片段: submissions

以下是我的设置和我想要完成的:

  • 我目前有一个谷歌表单,供用户提交信息,然后登录到谷歌表单中
  • 然后,我使用PyDrive将Google工作表的内容保存为csv
  • Pandas然后读取该csv,并根据特定标准删除csv中的数据
  • 在那之后,我使用PyDrive将“固定”csv重新上传到Google工作表,保存旧的csv
问题是:

每当我这样做时,它就会终止Google表单和Google表单之间的链接。有什么方法可以保留此链接或重新链接表单和工作表

下面是我一直在玩的代码片段:

submissions_data = drive.CreateFile({'id': ext['SUBMISSIONS_ID']})
submissions_data.GetContentFile("data.csv", mimetype = "text/csv")
df = pd.read_csv("data.csv")
df.drop([0],inplace=True)
df.to_csv("data.csv", index=False)
submissions_data.SetContentFile("data.csv")`
最好是,我想找到一种使用PyDrive实现这一点的方法,但在这一点上,任何东西都可以工作。感谢您的帮助!谢谢大家!

将Google Drive API与oauth2client和gspread一起使用,直接更新现有的电子表格

  • 去医院。创建一个新项目。单击启用 API
  • 启用。创建凭据 用于Web服务器访问应用程序数据
  • 命名服务帐户并授予其项目编辑器角色
  • 下载JSON文件
  • 将JSON文件复制到代码目录,并将其重命名为 client_secret.json
  • 在client_secret.json中查找client_电子邮件。返回电子表格,单击右上角的“共享”按钮,然后将客户端电子邮件粘贴到“人员”字段中,以授予其编辑权限。点击发送
  • 您可以通过更改特定单元格写入电子表格:

    sheet.update_cell(1, 1, "I just wrote to a spreadsheet using Python!")
    
    也可以在电子表格中插入一行:

    row = ["I'm","inserting","a","row","into","a,","Spreadsheet","with","Python"]
    index = 1
    sheet.insert_row(row, index)
    

    查看这些函数以及几十个其他函数的完整详细信息。

    您是在创建新文件而不是更新现有文件吗?@DaImTo我肯定是的,但我认为这是我能根据
    sheet.update_cell(1, 1, "I just wrote to a spreadsheet using Python!")
    
    row = ["I'm","inserting","a","row","into","a,","Spreadsheet","with","Python"]
    index = 1
    sheet.insert_row(row, index)