Created
October 21, 2024 12:40
-
-
Save devmnj/d06e9944b79f40a8bb721731f8a95718 to your computer and use it in GitHub Desktop.
Load google sheet data into panda frame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load data frame in google sheet | |
import gspread | |
from google.oauth2.service_account import Credentials | |
from google.auth import default | |
# Define the scope of access you need | |
scope = ['https://spreadsheets.google.com/feeds', | |
'https://www.googleapis.com/auth/drive'] | |
creds, _ = default() | |
client = gspread.authorize(creds) | |
spreadsheet = client.open('data_sheet') | |
worksheet = spreadsheet.worksheet('data') | |
data = worksheet.get_all_values() | |
df = pd.DataFrame(data[1:], columns=data[0]) | |
# Convert relevant columns to numeric types | |
df['PE_ratio'] = pd.to_numeric(df['PE_ratio'], errors='coerce') | |
df['Sharpe_ratio'] = pd.to_numeric(df['Sharpe_ratio'], errors='coerce') | |
df['Alpha'] = pd.to_numeric(df['Alpha'], errors='coerce') | |
df['Beta'] = pd.to_numeric(df['Beta'], errors='coerce') | |
df.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment