将 pandas 数据框附加到 Google 电子表格 [英] Appending pandas Data Frame to Google spreadsheet
本文介绍了将 pandas 数据框附加到 Google 电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
案例:我的脚本返回一个数据框,该数据框必须作为新的数据行附加到现有的谷歌电子表格中.截至目前,我通过 gspread 将数据框附加为多个单行.
Case: My script returns a data frame that needs has to be appended to an existing google spreadsheet as new rows of data.As of now, I'm appending a data frame as multiple single rows through gspread.
我的代码:
import gspread
import pandas as pd
df = pd.DataFrame()
# After some processing a non-empty data frame has been created.
output_conn = gc.open("SheetName").worksheet("xyz")
# Here 'SheetName' is google spreadsheet and 'xyz' is sheet in the workbook
for i, row in df.iterrows():
output_conn.append_row(row)
有没有办法附加整个数据框而不是多个单行?
Is there a way to append entire data-frame rather than multiple single rows?
推荐答案
我可以推荐 gspread-数据框
:
I can recommend gspread-dataframe
:
import gspread_dataframe as gd
# Connecting with `gspread` here
ws = gc.open("SheetName").worksheet("xyz")
existing = gd.get_as_dataframe(ws)
updated = existing.append(your_new_data)
gd.set_with_dataframe(ws, updated)
这篇关于将 pandas 数据框附加到 Google 电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文