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
from fuzzywuzzy import process | |
def find_best_match(misspelled, correct_names): | |
closest, ratio = process.extractOne(misspelled, correct_names) | |
return closest | |
print(find_best_match('noo yurk', ['New York', 'Boston', 'Washington'])) |
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
from os import listdir | |
from os.path import isfile, join | |
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] |
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
function isEmpty(obj) { | |
for(var prop in obj) { | |
if(obj.hasOwnProperty(prop)) { | |
return false; | |
} | |
} | |
return JSON.stringify(obj) === JSON.stringify({}); | |
} |
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
df = df.groupby(['client_id','data_source'],as_index=False).agg({ | |
'client': 'first', | |
'currency': 'first', | |
'total_revenue': 'sum', | |
'total_accrual': 'sum', | |
'revenue': 'sum', | |
'media_cost': 'sum' | |
}) |
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
from datetime import datetime, timedelta | |
def last_x_days(days): | |
""" | |
INPUT: int, date range, number of days | |
OUTPUT: dict, of the date range | |
""" | |
t = datetime.today() | |
y = t - timedelta(days=1) | |
m = y - timedelta(days=days) | |
y_day = y.strftime("%Y%m%d") |
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 json | |
from datetime import datetime | |
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
from df2gspread import df2gspread as d2g | |
def upload_to_sheet(df,sheet_id, sheet_name): | |
scope = ['https://spreadsheets.google.com/feeds', | |
'https://www.googleapis.com/auth/drive'] | |
credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope) |
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
from bigquery_schema_generator.generate_schema import SchemaGenerator | |
import json | |
from datetime import datetime | |
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
from df2gspread import df2gspread as d2g | |
def report_output_helper(report_name, df, output): | |
report_name = report_name.lower().replace(" ", "") | |
date = datetime.today().strftime('%Y%m%d') |
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
from bigquery_schema_generator.generate_schema import SchemaGenerator | |
import json | |
from datetime import datetime | |
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
from df2gspread import df2gspread as d2g | |
def output_helper(data, output): | |
level = level.lower() | |
date = datetime.today().strftime('%Y%m%d') |
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
def flatten(d, parent_key='', sep='_'): | |
items = [] | |
for k, v in d.items(): | |
new_key = parent_key + sep + k if parent_key else k | |
if isinstance(v, MutableMapping): | |
items.extend(flatten(v, new_key, sep=sep).items()) | |
else: | |
items.append((new_key, v)) | |
return dict(items) |