Wednesday, September 2, 2020

Read google sheets in python

 Source: https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html



Follow steps in the link. Then use this code


import pandas as pd

import gspread

from oauth2client.service_account import ServiceAccountCredentials


utils_dir = '11_utils/'


# use creds to create a client to interact with the Google Drive API

#scope = ['https://spreadsheets.google.com/feeds']

scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]


creds = ServiceAccountCredentials.from_json_keyfile_name(utils_dir+'sheets_api.json', scope)

client = gspread.authorize(creds)


# Find a workbook by name and open the first sheet

# Make sure you use the right name here.

sheet = client.open("live_prices").sheet1

data = sheet.get_all_records()  # Get a list of all records




df = pd.DataFrame(data)


No comments:

Post a Comment

Loud fan of desktop

 Upon restart the fan of the desktop got loud again. I cleaned the desktop from the dust but it was still loud (Lower than the first sound) ...