Skip to content

Instantly share code, notes, and snippets.

@gary136
gary136 / price_variation.ipynb
Created March 24, 2020 15:07
price_variation.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gary136
gary136 / twstock.py
Last active August 23, 2020 10:07
twstock.py
import pandas as pd
import requests
import numpy as np
from io import StringIO
import time
import matplotlib.pyplot as plt
import html5lib
from datetime import datetime, timedelta
import calendar
import datetime as dt
@gary136
gary136 / sql_pseudo.sql
Last active January 5, 2020 09:34
sql_pseudo.sql
SELECT * FROM
(
上市公司財務比率 (FROM 損益表) 
UNION 
上櫃公司財務比率 (FROM 損益表)
) A
JOIN
(
上市公司財務比率 (FROM 資產負債表 / 現金流量表) 
UNION 
@gary136
gary136 / multiple_aplly_pandas.py
Created December 24, 2019 14:02
multiple_aplly_pandas.py
def add_key(x):
sku = x[0]
r_id = x[1]
for ele in sku:
ele['receipt_id'] = r_id
return sku
df['sku'] = df[['sku', 'receipt_id']].apply(add_key, axis=1)
@gary136
gary136 / word_frequency.py
Last active December 18, 2019 05:58
word_frequency.py
import time
import numpy as np
import requests
import pandas as pd
# prepare
url = 'https://raw.githubusercontent.com/hermitdave/FrequencyWords/master/content/2016/en/en_50k.txt'
r = requests.get(url)
d = r.text.split('\n')[:-1]
word = [t[0] if len(t)==2 else None for t in [i.split(' ') for i in d]]
@gary136
gary136 / TwStockIdvs.ipynb
Last active December 1, 2019 15:08
TwStockIdvs.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gary136
gary136 / gd2.py
Last active December 1, 2019 04:58
gd2.py
def func(xlist):
return 2*(xlist[0]-2.3)**2+3*(xlist[0]-4.1)*(xlist[1]-6.5)+5*(xlist[1]-8.0)**2
# functions
def partial_derivative(f, x_list, odr, epsilon = 1e-6, **kargs):
h_list = x_list.copy()
h_list[odr] = x_list[odr] + epsilon
fx = f(x_list, **kargs)
fh = f(h_list, **kargs)
@gary136
gary136 / gd1.py
Last active November 29, 2019 09:38
gd1.py
def test(xlist):
# xlist is the list of the variables we have, and in this particular instance we have two variables
return 2*xlist[0]**2+3*xlist[0]*xlist[1]+5*xlist[1]**2
# functions
def partial_derivative(f, x_list, odr, epsilon = 1e-6, **kargs):
# 此為模擬偏微分會有少量誤差
h_list = x_list.copy()
h_list[odr] = x_list[odr] + epsilon
@gary136
gary136 / vocabulary.py
Created November 21, 2019 14:08
vocabulary.py
def vocabulary(sample, start, end):
import string
p = sample.replace('-', ' ').translate(str.maketrans('', '', string.punctuation)).split()
p = [i.lower() for i in p]
p = [(i, df[df.word==i].index[0], list(df[df.word==i]['dic'])[0]) \
if i in np.array(df.word) else (i, 99999, 'N') for i in p]
w = np.array(list(set(p)))[:,0]
r = np.array(list(set(p)))[:,1].astype(int)
d = np.array(list(set(p)))[:,2]
d = pd.DataFrame({'word':w
@gary136
gary136 / word_filter.ipynb
Last active November 21, 2019 13:51
word_filter.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.