Created
September 18, 2020 11:54
-
-
Save robflaherty/247bb7490c60072add58ab1c0d9da65d to your computer and use it in GitHub Desktop.
Send pandas dataframe to Google Sheets
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 pandas as pd | |
from sheets import send_to_sheets | |
df = pd.DataFrame.from_dict(data, orient='index') | |
send_to_sheets(df, 'Optional Sheet Name') |
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 pygsheets | |
def send_to_sheets(data, name='Sheets API'): | |
gc = pygsheets.authorize(service_file='../credentials/sheet-credentials.json') | |
sh = gc.create(name) | |
wks = sh.sheet1 | |
wks.set_dataframe(data, 'A1', copy_index=True) | |
sh.share('[email protected]', role='writer', type='user', sendNotificationEmail=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a Google project, enable the Sheets and Drive APIs, create service account credentials.
Docs created in a service account can't be accessed through the web UI so we share the doc after creating with a regular Google account.