Skip to content

Instantly share code, notes, and snippets.

@danyashorokh
danyashorokh / copy from excel
Created May 30, 2017 10:26
Excel 2007 usage with Python
# Excel 2007
rb = xlrd.open_workbook(file_name, formatting_info=True)
sheet = rb.sheet_by_index(active_list)
keys = sheet.row_values(keys_row)
@danyashorokh
danyashorokh / [Python] [Selenium] Waiting for form using Selenium
Last active October 5, 2017 08:57
[Python] [Selenium] Waiting for form using Selenium
def wait_form(driver, type, path, one_time, max_time, final_text):
flag1 = 0
while (True):
if flag1 == max_time:
print(final_text + "\n")
break
driver.close()
sys.exit(1)
else:
try:
@danyashorokh
danyashorokh / [Python] [Selenium] Scrolling to element
Last active October 5, 2017 09:02
[Python] [Selenium] Scrolling to element
def scroll_to(driver, type ,path):
if type == "xpath":
elem = driver.find_element_by_xpath(path)
if type == "id":
elem = driver.find_element_by_css_selector(path)
loc = elem.location
point = "window.scrollTo(0, "+str(loc["y"])+")"
driver.execute_script(point)
@danyashorokh
danyashorokh / [Python] Open file python
Last active May 4, 2019 01:35
[Python] Open file python
fi = open('input.txt','r')
e_list = []
my_str = ""
for line in fi:
my_str += line
e_list = my_str.split("\n")
print(e_list)
@danyashorokh
danyashorokh / [Python] Tuning model params (GridSearchCV)
Last active October 5, 2017 08:58
[Python] Tuning model params (GridSearchCV)
param_test1 = {'subsample': [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]}
gsearch1 = GridSearchCV(estimator = ensemble.GradientBoostingClassifier(n_estimators=600, learning_rate=0.04, max_depth=5,
max_leaf_nodes=5, random_state=2, min_samples_leaf=1, min_samples_split=300, max_features='sqrt', verbose=1, loss='exponential'),
param_grid=param_test1, scoring='roc_auc', n_jobs=4, iid=False, cv=5)
gsearch1.fit(X_train, y_train)
print(gsearch1.best_params_, gsearch1.best_score_)
@danyashorokh
danyashorokh / [Python] Important model features
Last active October 5, 2017 08:56
[Python] Important model features
clf = ensemble.GradientBoostingClassifier(**BOOSTING_PARAMS)
clf.fit(X_train, y_train)
predictors = [x for x in df_fin.columns if x not in ['ID1', 'ID2']]
feat_imp = pd.Series(clf.feature_importances_, index=predictors).sort_values(ascending=False)
# print(feat_imp.axes, feat_imp.values)
with open('path', 'a') as f:
@danyashorokh
danyashorokh / [Python] Pymssql db request
Last active September 17, 2018 07:35
[Python] Pymssql db request
def execute_db(host,user,password,db,request):
res = []
conn = pymssql.connect(host, user, password, db)
# print("I AM IN DB!")
cur = conn.cursor()
cur.execute(request)
# res.append([i[0] for i in cur.description]) # columns names
for row in cur:
#print(row)
@danyashorokh
danyashorokh / [JS] Scroll page to element after reload
Last active October 5, 2017 09:00
[JS] Scroll page to element after reload
var main = function() {
var y = getCookie("scrollDown");
window.scroll(0, y);
delete_cookie("scrollDown");
document.cookie = "scrollDown=0";
function toCartClick(el) {
var offset = offset1(el);
// alert(offset);
@danyashorokh
danyashorokh / [Python] Features correlation
Last active October 16, 2017 15:13
[Python] Features correlation
import pandas as pd
pd.set_option('expand_frame_repr', False)
def calc_corr(A, B):
return "{:0.2f}".format(A.corr(B))
df = pd.read_excel('input.xlsx')
print(df.head())
@danyashorokh
danyashorokh / [Python] Get actual currency rates (api)
Created October 5, 2017 08:53
[Python] Get actual currency rates (api)
# https://www.exchangerate-api.com
import requests
proxies = {
"https": "https://User:Password@fx-proxy:8080",
}
api_key = 'pifpaf'
# Where USD is the base currency you want to use
url = 'https://v3.exchangerate-api.com/bulk/' + api_key + '/USD'