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
source ~/shrink_venv/bin/activate | |
cd $VIRTUAL_ENV/lib/python3.6/site-packages | |
zip -r9 ~/CreateThumbnail.zip * | |
cd ~ | |
zip -g CreateThumbnail.zip CreateThumbnail.py | |
aws lambda update-function-code --function-name CreateThumbnail --zip-file fileb:///home/ec2-user/CreateThumbnail.zip |
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
from datetime import date | |
from dateutil.relativedelta import relativedelta, MO | |
# Relative delta replaces the day in the date you specify by day = 31. From this new date, weekday=MO(-1) specifies the last monday. | |
def get_last_mon_of_mth(dt): | |
print (dt + relativedelta(day=31, weekday=MO(-1))) | |
get_last_mon_of_mth(date(2018, 12, 30)) | |
get_last_mon_of_mth(date(2019, 6, 4)) |
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
from datetime import date | |
from dateutil.relativedelta import relativedelta, MO | |
# Relative delta replaces the day in the date you specify by day = 1. From this new date, weekday=MO(+1) specifies the 1st Monday. | |
def get_first_mon_of_mth(dt): | |
print (dt + relativedelta(day=1, weekday=MO(+1))) | |
get_first_mon_of_mth(date(2018, 12, 30)) | |
get_first_mon_of_mth(date(2019, 6, 4)) |
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
import pandas as pd | |
import numpy as np | |
import redis | |
import pyodbc | |
from time import time | |
from datetime import date, timedelta, datetime | |
r = redis.Redis(host='localhost', port=6379, db=0) | |
dt_last = datetime.strptime(r.get("last_update_time").decode(), '%Y-%m-%d %H:%M:%S') | |
dt_now = datetime.now() |
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
import redis | |
import json | |
# Retrieve Redis Stored Values, if any for faster processing | |
anc_dict_320 = {} | |
r = redis.Redis(host='localhost', port=6379, db=0) | |
json_str_320 = r.get("anc_dict_320") | |
if json_str_320 is not None: | |
anc_dict_320 = json.loads(json_str_320) | |
print(anc_dict_320) |
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
import pyodbc | |
import pandas as pd | |
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017 | |
conn = pyodbc.connect( | |
r'DRIVER={ODBC Driver 17 for SQL Server};' | |
r'SERVER=mydbinstance.cazdl38iyoz0.ap-southeast-1.rds.amazonaws.com;' | |
r'DATABASE=testdb;' | |
r'UID=pier;' |
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
import numpy as np | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import matplotlib.style as style | |
style.use('ggplot') | |
f, ax1 = plt.subplots(1, 1, figsize=(20, 7), sharex=True) | |
df_mth_plot = pd.DataFrame(list(monthly_growth_dict.items()), columns=['Market', 'Average Monthly Growth Rate %']) | |
df_mth_plot = df_mth_plot.sort_values('Average Monthly Growth Rate %', ascending=False) |
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
import calendar | |
df_weekly_season['DOW_ENG'] = weekly_season['ds'].apply(lambda x : calendar.day_name[pd.to_datetime(x).weekday()]) | |
df_weekly_season['DOW'] = weekly_season['ds'].apply(lambda x : int(pd.to_datetime(x).strftime('%w'))) # SUN == 0 | |
df_weekly_season['DOW'] = weekly_season['ds'].apply(lambda x : int(pd.to_datetime(x).weekday()) # MON == 0 |
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
> yum install centos-release-scl | |
> yum info rh-python36 | |
> scl enable rh-python36 bash | |
> python --version | |
Run PySpark2 | |
> pyspark2 | |
Python 3.6.3 (default, Apr 26 2018, 13:16:02) |
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
#SettingWithCopyWarning: | |
#A value is trying to be set on a copy of a slice from a DataFrame. | |
#Try using .loc[row_indexer,col_indexer] = value instead | |
# assign was introduced in pandas 0.16 to deal with this false positive | |
# Instead of | |
df_weekly_season.loc[:, 'market'] = market | |
# or | |
df_weekly_season['market'] = market |