简体   繁体   English

Pandas Google 表格 API - append 数据帧

[英]Pandas Google sheet API - append data frames

I wrote a script that takes an excel file and transforms it into a data frame then upload its value to a google sheet.我编写了一个脚本,它采用 excel 文件并将其转换为数据框,然后将其值上传到谷歌表。 my problem is that I change the row range manually and I want it to append to the next row automatically我的问题是我手动更改行范围,我希望它自动 append 到下一行

    CLIENT_SECRET_FILE = r'path'
    API_SERVICE_NAME = 'sheets'
    API_VERSION = 'v4'
    SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
    gsheetId = 'id'
    
    service = Create_Service(CLIENT_SECRET_FILE, API_SERVICE_NAME, API_VERSION, SCOPES)
    
    def Export_Data_To_Sheets():
        
        URL = r'path'
        df = pd.read_excel(URL)
        df.replace(np.nan, '', inplace=True)
    
        response_date = service.spreadsheets().values().append(
            spreadsheetId=gsheetId,
            valueInputOption='RAW',
            range='Raw-Data!A25:N25', //here is what I want to fix
            body=dict(
                majorDimension='ROWS',
                values=df.T.reset_index().T.values.tolist())
        ).execute()


Export_Data_To_Sheets()

In this case, please remove :A25:N25 from range='Raw-Data:A25:N25' as follows.在这种情况下,请从range='Raw-Data:A25:N25'中删除:A25:N25 ,如下所示。

Modified script:修改后的脚本:

From: 从:
 range='Raw-Data:A25,N25',
To: 至:
 range='Raw-Data',
  • By this modification, values is appended to the sheet of Raw-Data .通过此修改, values将附加到Raw-Data表中。

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM