Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sebastianmurillonader/b7fd84a0935e0ca1b6f78b35800b1d57 to your computer and use it in GitHub Desktop.
Save sebastianmurillonader/b7fd84a0935e0ca1b6f78b35800b1d57 to your computer and use it in GitHub Desktop.
#Define scope of API.
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('./insertNameOfYourKeyFile.json', scope) #Get this file by activating the Google Sheets API from your Google account.
gc = gspread.authorize(credentials)
#Define spreadsheet variables.
spreadsheetKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
book = gc.open_by_key(spreadsheetKey)
worksheet = book.worksheet("hoja1")
table = worksheet.get_all_values()
#Convert table data into a dataframe
df = pd.DataFrame(table[1:], columns=table[0])
#Convert number strings to floats and ints
df = df.apply(pd.to_numeric, errors='ignore')
#Print first 5 rows.
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment