Created
November 21, 2017 06:26
-
-
Save thelazyliz/43874e19672d22e0be7dd26db8f2a37d to your computer and use it in GitHub Desktop.
read google spreadsheet using pandas
This file contains hidden or 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
import gspread | |
import pandas as pd | |
from oauth2client.service_account import ServiceAccountCredentials | |
def main(): | |
df_tracking = read_sheet('Olympus Labs tracking spreadsheet') | |
df_movement = read_sheet('Olympus Labs TG movement spreadsheet') | |
get_invites_count(df_movement, 366664457) # specific example of user_id given here | |
get_eth_address(df_tracking, 359780450) # specific example of user_id given here | |
return | |
def read_sheet(sheetname): | |
scope = ['https://spreadsheets.google.com/feeds'] | |
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope) | |
gc = gspread.authorize(creds) | |
sheet = gc.open(sheetname).sheet1 | |
df = pd.DataFrame(sheet.get_all_records()) | |
return df | |
def get_invites_count(df, user_id): | |
user_df = df[(df['user id'] == int(user_id)) & (df['type'] == 'invited')] | |
return user_df['member id'].unique().shape[0] | |
def get_eth_address(df, user_id): | |
user_df = df[df['id'] == int(user_id)] | |
return user_df.iloc[-1]['eth address'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment