Skip to content

Instantly share code, notes, and snippets.

@robflaherty
Created September 18, 2020 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robflaherty/247bb7490c60072add58ab1c0d9da65d to your computer and use it in GitHub Desktop.
Save robflaherty/247bb7490c60072add58ab1c0d9da65d to your computer and use it in GitHub Desktop.
Send pandas dataframe to Google Sheets
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')
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('youremail@gmail.com', role='writer', type='user', sendNotificationEmail=False)
@robflaherty
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment