[英]Python/Gspread How can I add column names while creating a worksheet?
#For creating a new-sheet
sheets.add_worksheet(title=sheetName, rows=df.shape[0], cols=df.shape[1])
#For appending
values = df.values.tolist()
sheets.values_append(sheetName, {'valueInputOption': 'USER_ENTERED'}, {'values': values})
It creates a new worksheet but there are no column names in it only the values.
它创建了一个新工作表,但其中没有列名,只有值。
In your script, how about the following modification?在你的脚本中,如何进行以下修改?
values = df.values.tolist()
values = [df.columns.values.tolist()] + df.values.tolist()
values
has the data including the header row.values
的数据包括 header 行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.