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
# 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.write(chunk) | |
#f.flush() commented by recommendation from J.F.Sebastian |
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
# Usage: currency value subtraction | |
def find_number(text): | |
if len(re.findall(r'\.',text)) == 0: | |
return float(re.findall(r'\d+',text.replace(",", ""))[0]) | |
else: | |
return float(re.findall(r'\d+\.\d+',text.replace(",", ""))[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
# Def Check Nan Function | |
# https://stackoverflow.com/questions/944700/how-can-i-check-for-nan-in-python | |
def is_nan(x): | |
return isinstance(x, float) and math.isnan(x) |
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
# 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] |
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 bs4 import BeautifulSoup | |
import requests, datetime | |
from tqdm import * | |
import pandas as pd | |
engine_bing = 'https://cn.bing.com/search?q=site%3Atianyancha.com+' | |
engine_baidu = 'https://www.baidu.com/s?wd=site%3A%20tianyancha.com%20' | |
def get_exact_name(name_list, name_column): | |
df = pd.read_excel(name_list,encoding='gb18030') |
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
df_cf["tradeDate"] = df_cf["tradeDate"].astype("datetime64[ns]") |
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
# Get current file path for migration consistency | |
path = os.getcwd().replace('\\','/') #r'%s' % os.getcwd().replace('\\','/') |
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 psutil | |
# Chrome App Kill | |
def kill_chrome(): | |
for proc in psutil.process_iter(): | |
if 'chrome.exe' in proc.name(): | |
proc.kill() |
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 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( | |
'https://gist.githubusercontent.com/chriddyp/' |
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 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 |
OlderNewer