如何使用 gspread python 在 google 工作表中将输出数据帧放在 D2 而不是 A1 中

how to place output data-frame in D2 instead of A1 in google sheets with gspread python

# accessing workbook
wb = gc.open_by_url('https://docs.google.com/spreadsheets/d/1LcFa9PDSjaL-Po47okWzLaUC4QUdtRSXzrgslTo6V7E/edit#gid=0')

# creating new worksheet
worksheet = wb.add_worksheet(title="A_worksheet", rows="100", cols="20")

# print df in new worksheet
sh = wb.worksheet('A_worksheet')
set_with_dataframe(sh, df)

我刚刚查看了 set_with_dataframe 的源代码。您可以将 rowcol 作为参数传递,默认值为 1,因此它写入的位置。尝试传递适当的值并检查。

def set_with_dataframe(worksheet,
                       dataframe,
                       row=1,
                       col=1,
                       include_index=False,
                       include_column_header=True,
                       resize=False,
                       allow_formulas=True):

希望对您有所帮助。