def write_csv(date): df_industry = read_industry_df() dfo = pd.read_excel(my_util.get_abs_path() + '/data/industry_quote/' + date + ".xlsx") df_merge = pd.merge(df_industry, dfo, how='right') df_merge.to_csv(my_util.get_abs_path() + '/docs/static/industry_quote/' + date + ".csv", index=False, encoding="utf-8")
def read_industry_stock_list(range_start, range_end): stock_list = [] stockxls = my_util.get_abs_path() + '/basicdata/industry.csv' with open(stockxls, 'rb') as f: book = open_workbook(stockxls) # print(open_workbook(file_contents=mmap(f.fileno(),0,access=ACCESS_READ))) sheet = book.sheet_by_index(0) for i in range(range_start, range_end): stock_list.append(sheet.cell_value(i, 0)) return stock_list
def append_reports_for_industry(industry, df_industry): for i in range(0, len(df_industry)): stock_code = df_industry.iloc[i]['stock_code'] df_cfs = pd.read_excel(get_abs_path() + '/data/cfs/cfs_' + stock_code + '.xlsx') # , skiprows=1 df_is = pd.read_excel(get_abs_path() + '/data/is/is_' + stock_code + '.xlsx') df_bs = pd.read_excel(get_abs_path() + '/data/bs/bs_' + stock_code + '.xlsx') df_cfs['stock_code'] = stock_code df_is['stock_code'] = stock_code df_bs['stock_code'] = stock_code stock_name = df_industry.iloc[i]['stock_name'] df_cfs['stock_name'] = stock_name df_is['stock_name'] = stock_name df_bs['stock_name'] = stock_name print("read:%s" % (stock_code)) if i == 0: df_cfs_all = df_cfs df_is_all = df_is df_bs_all = df_bs else: df_cfs_all = df_cfs_all.append(df_cfs) df_is_all = df_is_all.append(df_is) df_bs_all = df_bs_all.append(df_bs) df_cfs_all.fillna(0, inplace=True) df_is_all.fillna(0, inplace=True) df_bs_all.fillna(0, inplace=True) # print(df_cfs.keys()) df_cfs_all.to_excel(get_abs_path() + '/data/cfs_' + industry + '.xlsx') df_is_all.to_excel(get_abs_path() + '/data/is_' + industry + '.xlsx') df_bs_all.to_excel(get_abs_path() + '/data/bs_' + industry + '.xlsx')
def read_stock_list(sh_sz, range_start, range_end): stock_list = [] stockxls = my_util.get_abs_path() + '/basicdata/stocks.xlsx' with open(stockxls, 'rb') as f: book = open_workbook(stockxls) # print(open_workbook(file_contents=mmap(f.fileno(),0,access=ACCESS_READ))) # sheet = book.sheet_by_index(0) sheet = book.sheet_by_name(u'SH') if sh_sz == 'SZ': sheet = book.sheet_by_name(u'SZ') for i in range(range_start, range_end): stock_list.append(sheet.cell_value(i, 0)) return stock_list
def get_merged_csrc_industry(): dfo1 = pd.read_excel(my_util.get_abs_path() + '/basicdata/csrc_industry.xlsx', skiprows=1, usecols='B,C,D,E') df_industry2 = dfo1[dfo1['level'] == 2] df_industry2.rename(columns={'code': 'industry2_code'}, inplace=True) df_industry2.rename(columns={'name': 'industry2_name'}, inplace=True) del df_industry2['level'] df_industry1 = dfo1[dfo1['level'] == 1] df_industry1.rename(columns={'code': 'industry1_code'}, inplace=True) df_industry1.rename(columns={'name': 'industry1_name'}, inplace=True) del df_industry1['level'] del df_industry1['parent_code'] df_industry = pd.merge(df_industry1, df_industry2, left_on='industry1_code', right_on='parent_code', how='outer') del df_industry['parent_code'] return df_industry
from mpl_toolkits.mplot3d import axes3d import industry import chart.is_chart as is_chart import chart.bs_chart as bs_chart import chart.cfs_chart as cfs_chart import chart.is_cfs_chart as is_cfs_chart import stock_reader from matplotlib.font_manager import FontProperties import data_preprocessor from matplotlib import rcParams from datetime import datetime import my_util import os root_dir = my_util.get_abs_path() def draw_industry_is_cfs_bs_subplot(ax, df, x, str_stock_code=''): width = 0.10 # cfs var if str_stock_code == '': stock_code = df['stock_code'] stock_name = df['stock_name_cfs'] bizcashinfl = df['sub_total_of_ci_from_oa'] bizcashoutf = df['sub_total_of_cos_from_oa'] mananetr = df['ncf_from_oa'] invcashinfl = df['sub_total_of_ci_from_ia'] invcashoutf = df['sub_total_of_cos_from_ia'] invnetcashflow = df['ncf_from_ia']
def get_file_name(name): # xueqiu_base.create_dir_if_not_there('../','data') # xueqiu_base.create_dir_if_not_there('../data', 'bs') return my_util.get_abs_path() + '/data/bs/bs_' + name + '.xlsx'
def read_sw_industry_stock_df_by_code(stock_code): dfo = pd.read_csv(my_util.get_abs_path() + '/basicdata/SwClass.csv') df = dfo[dfo['stock_code'] == stock_code] return df
def read_sw_industry_stock_df(industry): dfo = pd.read_csv(my_util.get_abs_path() + '/basicdata/SwClass.csv') df = dfo[dfo['industry'] == industry] return df
def read_industry_df(): dfo = pd.read_csv(my_util.get_abs_path() + '/basicdata/xueqiu_industry.csv') return dfo
import sys sys.path.append('../xueqiu') sys.path.append('../') sys.path.append('../chart') sys.path.append('.') import xueqiu.xueqiu_industry_price as xueqiu_industry_price import time import my_util if __name__ == "__main__": date_str = time.strftime("%Y-%m-%d", time.localtime()) print('today is ' + date_str) industry_df = xueqiu_industry_price.read_industry_df() data = xueqiu_industry_price.get_xueqiu_industry_quote( industry_df, my_util.get_abs_path() + '/data/industry_quote/' + date_str) xueqiu_industry_price.write_csv(date_str)
def get_file_name(name): # xueqiu_base.create_dir_if_not_there('../','data') # xueqiu_base.create_dir_if_not_there('../data', 'is') # root_dir = os.path.dirname(os.path.abspath('./stock-analyzer')) return my_util.get_abs_path() + '/data/is/is_' + name + '.xlsx'