Skip to content

Instantly share code, notes, and snippets.

View talsan's full-sized avatar
👋

Tal Sansani talsan

👋
  • Off-Script Systems, LLC
  • Oakland, CA
View GitHub Profile
@talsan
talsan / brinson.py
Created January 13, 2021 18:13
bare bones brinson attribution
import pandas as pd
from typing import Union
# input parameters
asset_data = pd.read('./input_file.csv')
bm_wts_col = 'bm_wt'
por_wts_col = 'por_wt'
grouping_level = 'sector'
rets_col = 'ret_1mf'
@talsan
talsan / query_athena.py
Last active October 29, 2023 20:07
input an athena query; return a pandas dataframe
import boto3
import time
from botocore.exceptions import ClientError
import pandas as pd
from io import BytesIO
from datetime import datetime
import pprint
import logging
log = logging.getLogger(__name__)
@talsan
talsan / read_gzip_from_s3.py
Created July 4, 2020 05:11
Download and Read GZIP File from S3
import boto3
import gzip
from io import BytesIO
import shutil
aws_session = boto3.Session(aws_access_key_id='', ### AWS ACCESS KEY HERE
aws_secret_access_key='') ### AWS SECRET KEY HERE
s3_client = aws_session.client('s3')
@talsan
talsan / list_s3_keys.py
Created July 4, 2020 05:03
Get a list of S3 filenames (keys) in a bucket or sub-directory (prefix)
import boto3
import re
aws_session = boto3.Session(aws_access_key_id='', ### AWS ACCESS KEY HERE
aws_secret_access_key='') ### AWS SECRET KEY HERE
s3_client = aws_session.client('s3')
def list_keys(bucket, prefix='', suffix='', full_path=True, remove_ext=False):
@talsan
talsan / upload_gzip_to_s3.py
Created July 4, 2020 05:00
Upload GZIP File to S3
import boto3
import gzip
from io import BytesIO
import shutil
aws_session = boto3.Session(aws_access_key_id='', ### AWS ACCESS KEY HERE
aws_secret_access_key='') ### AWS SECRET KEY HERE
s3_client = aws_session.client('s3')