Answer a question

I managed to read data from a Google Sheet file using this method:

# ACCES GOOGLE SHEET
googleSheetId = 'myGoogleSheetId'
workSheetName = 'mySheetName'
URL = 'https://docs.google.com/spreadsheets/d/{0}/gviz/tq?tqx=out:csv&sheet={1}'.format(
    googleSheetId,
    workSheetName
)
df = pd.read_csv(URL)

However, after generating a pd.DataFrame that fetches info from the web using selenium, I need to append that data to the Google Sheet.

Question: Do you know a way to export that DataFrame to Google Sheets?

Answers

Yes, there is a module called "gspread". Just install it with pip and import it into your script.

Here you can find the documentation: https://gspread.readthedocs.io/en/latest/

In particular their section on Examples of gspread with pandas.

worksheet.update([dataframe.columns.values.tolist()] + dataframe.values.tolist())
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐