Preview:
def open_google_sheet(wookbookname,sheet_num=0):
‘’’
Requests a Google sheet saved as ‘workbookname’ using credentials for developer email.
Credentials for Google API are stored in /Users/#########/.config/gspread/service_account.json
sheetname = The name of the Google sheet file as seen on Google. Entered as a string.
sheet_num = The sheet number for the Google Sheet. Defaults to 0 if no entry.
Parameters
 — — — — — 
workbookname: The name of the Google Sheet that you intend to open
sheet_num: The number of the sheet in the Google Sheet you intend to open (numbering begins at 0)
Returns
 — — — -
DataFrame: A DataFrame of the information contained in the Google Sheet
‘’’
scope = [‘https://spreadsheets.google.com/feeds',
‘https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
‘/Users/######/.config/gspread/service_account.json’, scope)
#If credentials change, must change json file.
gc = gspread.authorize(credentials)
wks = gc.open(f”{workbookname}”).get_worksheet(sheet_num)
data = wks.get_all_values()
headers = data.pop(0)
df = pd.DataFrame(data, columns=headers)
return df
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter