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
\s(.*) |
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
# https://towardsdatascience.com/time-series-forecasting-based-on-the-trend-and-seasonal-components-26b92866e548 | |
from statsmodels.tsa.seasonal import seasonal_decompose | |
def decompose(df): | |
decomposition = sm.tsa.seasonal_decompose(df, model='additive', freq=365) | |
trend = decomposition.trend | |
seasonal = decomposition.seasonal | |
residual = decomposition.resid | |
fig = decomposition.plot() |
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
np.select(condlist, choicelist, default=0) | |
# EXAMPLE | |
CondList = [ | |
(data['FBG'] >= 126) | (data['HbA1c'] >= 6.5), | |
((data['FBG'] < 126) & (data['FBG'] >= 100)) | ((data['HbA1c'] < 6.5) & (data['HbA1c'] >= 5.7)), | |
(data['FBG'] < 100) | (data['HbA1c'] < 5.7)] | |
ChoiceList = [2,1,0] | |
data.insert(1,'DM',np.select(CondList,ChoiceList,default=3)) |
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 math | |
def convert_size(size_bytes): | |
if size_bytes == 0: | |
return "0B" | |
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") | |
i = int(math.floor(math.log(size_bytes, 1024))) | |
p = math.pow(1024, i) | |
s = round(size_bytes / p, 2) | |
return "%s %s" % (s, size_name[i]) |
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
-- In Teradata, you can use a Stored Procedure to loop over SQL statements with variable values. | |
-- Here is an example of how you might do this: | |
REPLACE PROCEDURE Test (OUT r2 VARCHAR (3000)) | |
BEGIN | |
DECLARE RowCnt INT; | |
DECLARE i INT; | |
DECLARE CurrRow INT; | |
DECLARE r VARCHAR (3000); |
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
declare @SomeTempTable table | |
( | |
Column1, | |
Column2 | |
) | |
declare @FiscalWeek int = 1 | |
declare @FinalWeek int = ? | |
while @FiscalWeek <= @FinalWeek | |
begin | |
insert into @SomeTempTable |
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
# use standard HTML comments | |
<!-- This is commented out. --> |
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
# Find | |
\((.*) | |
# Replace | |
($1) AS $1 | |
# Example | |
,SUM(rtn_ttl_u | |
,SUM(rtn_ttl_u) AS rtn_ttl_u |
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
# standard imports | |
import os | |
import logging | |
import time | |
import yaml | |
# third party imports | |
import pandas as pd | |
import dask.dataframe as dd | |
from dask.distributed import Client, LocalCluster |
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 os | |
import multiprocessing | |
# get the number of logical cpu cores | |
n_cores = os.cpu_count() | |
n_cores = multiprocessing.cpu_count() | |
# get total physical memory | |
# https://stackoverflow.com/questions/22102999/get-total-physical-memory-in-python | |
# For MacOS, as per user reports, this works with Python 3.7 but not with Python 3.8 |
NewerOlder