3 Essential Tips to Start Using Google Data Studio | by Andrew Mooney | May, 2021 | Towards Data Science Part 1

PHOTO EMBED

Fri Jun 25 2021 22:12:28 GMT+0000 (Coordinated Universal Time)

Saved by @admariner

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
content_copyCOPY

https://towardsdatascience.com/3-essential-tips-to-start-using-google-data-studio-93334a403d11