Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.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 如何使用pygsheets上载工作表_Python_Json_Google Sheets Api_Pygsheets - Fatal编程技术网

Python 如何使用pygsheets上载工作表

Python 如何使用pygsheets上载工作表,python,json,google-sheets-api,pygsheets,Python,Json,Google Sheets Api,Pygsheets,我正在使用google sheets api v4的包装器 我有一个小脚本,试图选择一个json表上传到GoogleSheets工作表。文件名由以下部分组成: spreadsheetname_year_month_xxx.json 守则: import tkinter as tk import tkFileDialog import pygsheets root = tk.Tk() root.withdraw() file_path = tkFileDialog.askopenfilena

我正在使用google sheets api v4的包装器

我有一个小脚本,试图选择一个json表上传到GoogleSheets工作表。文件名由以下部分组成:

spreadsheetname_year_month_xxx.json
守则:

import tkinter as tk
import tkFileDialog
import pygsheets


root = tk.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
print file_path
file_name = file_path.split('/')[-1]
print file_name
file_name_segments = file_name.split('_')
spreadsheet = file_name_segments[0]
worksheet = file_name_segments[1]+'_'+file_name_segments[2]

gc = pygsheets.authorize(outh_file='client_secret_xxxxxx.apps.googleusercontent.com.json')

ssheet = gc.open(spreadsheet)
ws = ssheet.add_worksheet(worksheet(ssheet,str(raw_input(file_path))))
文件路径导致生成的json文件,如下所示:

{
  "count": 12, 
  "results": [
    {
      "case": "abc1", 
      "case_name": "invalid", 
      "case_type": "invalid", 

    }, 
    {
      "case": "abc2", 
      "case_name": "invalid", 
      "case_type": "invalid", 
      },
............
我得到:

File "upload_to_google_sheets.py", line 27, in <module>
ws = ssheet.add_worksheet(worksheet(ssheet,str(raw_input(file_path))))
TypeError: 'unicode' object is not callable
正如您所看到的,我试图用json数据实例化一个工作表。我做错了什么?

JsonSheet参数不是用于工作表的值,而是用于指定工作表的属性,因此应为格式


由于直接将json转换为电子表格相当不明确,您需要首先将其转换为numpy数组矩阵或数据帧。然后,您可以使用set_as_df of just update_值来更新电子表格。

您确定这样做正确吗?由于jsonSheet参数包含工作表的属性,因此应采用此格式。您是否正在尝试使用json文档中的值更新工作表?谢谢您的快速回答。我已经按照您的要求创建了pygsheets标记。我真的很感激你在这里的工作。我将调查numpy阵列和dfs。如果我可以问一个后续问题:我有很多CSV我想上传,你会推荐什么方法使用你的库?我说的numpy数组只是一个列表列表。关于csv,您可以使用csv模块读取csv作为列表矩阵列表,并使用更新单元格。或者您可以使用pandas read_csv读取csv并将_设置为_df。我建议使用csv模块,因为它可能会快一点,而且熊猫支持可能会被删除,因为它会大大增加导入时间。谢谢。我一定错过了,但是pygsheets中的csv模块在哪里?pygsheets只需要一个通用矩阵,您可以使用csv模块将csv读入该格式。如果你有时间,我会跟进的。