【发布时间】:2021-10-12 15:31:51
【问题描述】:
我正在从事一种自动化工作,包括将数据帧的值发送到谷歌表格,以下是我的示例数据帧代码,类似于我正在处理的代码:
#Creates a dictionary containing values for 1 column to be used in pandas dataframe
col = {'id':["1"],'name':["Juan"], 'code':["1563"], 'group':["3"], 'class':["A"]}
#Creates a pandas dataframe
df = pd.DataFrame(col)
df
我只需要将数据帧值发送到谷歌表,没有标题,这只是我正在使用的数据的一个示例,当然我需要数据帧中的标题,因为我正在做一些列转换由于数据来自 API。
这是将数据框发送到谷歌表的代码:
import gspread
from gspread_dataframe import set_with_dataframe
gc = gspread.service_account(filename='API_creds.json')
sheet = gc.open_by_key('SHEET_ID')
# Sending values from aimleap dataframe google sheet
row=1
col=1
worksheet = sheet.get_worksheet(0)
set_with_dataframe(worksheet,df,row,col)
通过set_with_dataframe(worksheet,df,row,col) 将数据框发送到工作表后,工作表会使用包括标题在内的数据框进行更新,我只需要使用数据框的值来更新工作表,如何将set_with_dataframe() 的参数修改为实现这个?
这是发送数据帧时的样子:
【问题讨论】:
标签: python google-sheets gspread