pygsheets set_dataframe:IndexError:列表索引超出范围

时间:2018-08-13 15:34:23

标签: python pandas pygsheets

我正在尝试使用pygsheets将数据框放入Google表格中。但是,我得到列表索引超出范围错误,并且找不到任何解决方案。

我的数据框:

                   year     month has product?  Sold
year   month                                       
2017.0 November  2017.0  November           x  23.0
       December  2017.0  December           x  34.0
2018.0 January   2018.0   January           x  28.0
       February  2018.0  February           x  22.0
       March     2018.0     March           v  24.0
       April     2018.0     April           v  32.0
       May       2018.0       May           v  27.0
       June      2018.0      June           v  20.0
       July      2018.0      July           v  15.0

我正在通过串联以下3个其他数据帧来构造此数据帧:

df3 = pd.concat([year, month,hasProduct,sales],axis=1).reindex(year.index)

然后我在以下函数中使用此数据框:

def updateSheet():

  df=dictToPandas()

  gc = pygsheets.authorize(service_file='secret.json')
  sh = gc.open("Reports")
  wks = sh.worksheet_by_title("test_sheet") 
  wks.set_dataframe(df,'A2')

这将产生以下回溯:

Traceback (most recent call last):



File "C:\Users\Laila\Desktop\8.py", line 163, in <module>
    updateSheet()
  File "C:\Users\Laila\Desktop\8.py", line 146, in updateSheet
    wks.set_dataframe(df,'A2')
  File "C:\Users\Laila\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygsheets\worksheet.py", line 979, in set_dataframe
    heads[i].append(col_item)
IndexError: list index out of range
[Finished in 19.4s]

我找不到错误的出处,不胜感激。

0 个答案:

没有答案