Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sebastianmurillonader/b7fd84a0935e0ca1b6f78b35800b1d57 to your computer and use it in GitHub Desktop.

Select an option

Save sebastianmurillonader/b7fd84a0935e0ca1b6f78b35800b1d57 to your computer and use it in GitHub Desktop.

Revisions

  1. sebastianmurillonader created this gist Jul 10, 2020.
    21 changes: 21 additions & 0 deletions ProcessComparisonPairGrid-SetGoogleSheetsAPI.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #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()