【问题标题】:How do I export data frames I have created in Google Colab with pandas, to a new Google Sheets file?How do I export data frames I have created in Google Colab with pandas, to a new Google Sheets file?
【发布时间】:2022-12-28 06:30:27
【问题描述】:

I have read countless posts on here about using gspread to output data to Google Sheets, but everytime I try an example, it doesn't work for me.

Basically I am currently reading in data from an existing Google Sheets doc, working on it with Pandas, then I want to output the data to a brand new Google Sheets doc.

I have figured out how to create a new Google Sheets doc, a new worksheet and how to manually update individual cell ranges but what I need to do is export a data frame to the sheet.

I start my script off with the following code block. I understand there are different ways of working with the API but this way worked for me:

from google.colab import auth
auth.authenticate_user()

import gspread
from google.auth import default
creds, _ = default()

gc = gspread.authorize(creds)

After all the work I do with the data, I now just need to know how to take a df I create e.g. a simple 2 column df and put it into a new Google Sheets doc without getting errors.

I have read the documentation and countless posts but I just can't seem to get it to work. There are other things I need to figure out how to do with gspread but this is a blocker I have right now.

Any help with this would be greatly appreciated.

Thanks for taking the time to read.

【问题讨论】:

    标签: python pandas google-sheets gspread


    【解决方案1】:

    Use this gspread pandas tutorial - maybe it will help you :

    https://docs.gspread.org/en/v5.7.0/user-guide.html#using-gspread-with-pandas

    This topic is also discussed on my profile.

    【讨论】: