-
-
Save iTrauco/4bbcb86f31565d37f33d5921a3ab22ce to your computer and use it in GitHub Desktop.
Upload pandas dataframe Google Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from datetime import datetime | |
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
from df2gspread import df2gspread as d2g | |
def upload_to_sheet(df,sheet_id, sheet_name): | |
scope = ['https://spreadsheets.google.com/feeds', | |
'https://www.googleapis.com/auth/drive'] | |
credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope) | |
spreadsheet_key = sheet_id | |
wks_name = sheet_name | |
if not df.empty: | |
d2g.upload(df, spreadsheet_key, wks_name, credentials=credentials, row_names=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment