Skip to content

Instantly share code, notes, and snippets.


Qiao Zhang qzcool

Block or report user

Report or block qzcool

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
qzcool /
Last active Jun 23, 2019
Get the calendar position of start and end date of any date range
import datetime
date_start = datetime.datetime.strptime('2019-09-26', '%Y-%m-%d').date()
date_end = date_start + datetime.timedelta(days=1)
# 每月第一天的星期日名称,并推算date_start日和T+1日的表格位置
def get_calender_position_x(date):
position_x = date.weekday() + 1
if position_x == 7:
position_x = 0
position_x += 1
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
app = dash.Dash()
df = pd.read_csv(
qzcool / [Windows] Chrome Program Kill Function
Last active Jun 14, 2018
[Windows] program kill functions, currently including Excel and Chrome.
View [Windows] Chrome Program Kill Function
import psutil
# Chrome App Kill
def kill_chrome():
for proc in psutil.process_iter():
if 'chrome.exe' in
qzcool / Get Current File Path for Migration Consistency
Last active Jun 14, 2018
Get current file path for migration consistency.
View Get Current File Path for Migration Consistency
# Get current file path for migration consistency
path = os.getcwd().replace('\\','/') #r'%s' % os.getcwd().replace('\\','/')
qzcool / Change Data Type from Obect to Datetime
Created May 21, 2018
Change Data Type from Obect to Datetime
View Change Data Type from Obect to Datetime
df_cf["tradeDate"] = df_cf["tradeDate"].astype("datetime64[ns]")
qzcool / 公司标准名称清洗
Created May 3, 2018
View 公司标准名称清洗
from bs4 import BeautifulSoup
import requests, datetime
from tqdm import *
import pandas as pd
engine_bing = ''
engine_baidu = ''
def get_exact_name(name_list, name_column):
df = pd.read_excel(name_list,encoding='gb18030')
qzcool / Get Position Function
Last active May 3, 2018
Get Position Function: 增加程序对数据源结构变化的稳定性
View Get Position Function
# Def get position function: 增加程序对数据源结构变化的稳定性
def f_p(df, feature):
feature_list = df.iloc[:,0].get_values().tolist() # 第一列为特征名称,Index为连续自然数
return [i for i,x in enumerate(feature_list) if x == feature][0]
View Check Nan Function
# Def Check Nan Function
def is_nan(x):
return isinstance(x, float) and math.isnan(x)
qzcool / Currency Value Subtraction
Last active May 3, 2018
Subtract Numers (Int/Float) from a String
View Currency Value Subtraction
# Usage: currency value subtraction
def find_number(text):
if len(re.findall(r'\.',text)) == 0:
return float(re.findall(r'\d+',text.replace(",", ""))[0])
return float(re.findall(r'\d+\.\d+',text.replace(",", ""))[0])
qzcool / Download File Common Function
Last active May 3, 2018
[Python 3.6] Download File Common Function
View Download File Common Function
# Download File Common Function
def download_file(url, path):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
#f.flush() commented by recommendation from J.F.Sebastian
You can’t perform that action at this time.